Hi,
I’m trying to update an old project and I’m having a problem with CORS.
Yet I’m using middleware that adds the right headers as explained in @odan ebook.
But it doesn’t work and the headers aren’t added at the end of the response. As if they were deleted after the middleware.
There is the code : LaBaude32 / pvappcore-test · GitLab
Does anyone have any idea what the problem is?
Thx !
noxx
2
Hi, should you not set the headers for the preflight response?
if ($request->getMethod() === 'OPTIONS') {
return $this->responseFactory->createResponse();
}
odan
3
It looks like a bug in the eBook. I will fix it as soon as possible.
To add the preflight response CORS headers, change:
if ($request->getMethod() === 'OPTIONS') {
return $this->responseFactory->createResponse();
}
to
if ($request->getMethod() === 'OPTIONS') {
$response = $this->responseFactory->createResponse();
}
2 Likes
Effectively, it works now !
Thx a lot !