You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
I am using Docker + Nginx to proxy requests between my frontend React project on localhost to backend Laravel API on localhost:8080.
I try to register a new user from the frontend on localhost/register to Laravel localhost:8080/api/register
The GET request to sanctum/csrf-cookie works and it sets the XSRF-TOKEN
But then I try to send POST request to register a user and I get CORS error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at http://localhost:8080/api/register. (Reason:
CORS header ‘Access-Control-Allow-Origin’ is missing)
And despite this message, the user is registered successfully. But the error still appears because indeed the response does not contain the ‘Access-Control-Allow-Origin’ header.
I'm not sure if something in the middle (nginx, docker) is blocking it, but the GET request clearly works because when I try to change the allowed_origins in my cors.php file it throws an error.
I am using Docker + Nginx to proxy requests between my frontend React project on
localhost
to backend Laravel API onlocalhost:8080
.I try to register a new user from the frontend on
localhost/register
to Laravellocalhost:8080/api/register
The
GET
request tosanctum/csrf-cookie
works and it sets theXSRF-TOKEN
But then I try to send
POST
request to register a user and I get CORS error:And despite this message, the user is registered successfully. But the error still appears because indeed the response does not contain the ‘Access-Control-Allow-Origin’ header.
I'm not sure if something in the middle (nginx, docker) is blocking it, but the
GET
request clearly works because when I try to change theallowed_origins
in mycors.php
file it throws an error.This is my
cors.php
:This is the
OPTIONS
response headers:This is the
OPTIONS
request headers:This is the
POST
response headers:This is the
POST
request headers:In order to fix this CORS error I added the following to my nginx config:
So now my nginx config file looks like this:
So manually telling nginx to send back these headers for the
POST
request work, but why I don't get this issue forGET
andOPTIONS
?The text was updated successfully, but these errors were encountered: