Next.js in production giving CORS error
Unanswered
Yellow Warbler posted this in #help-forum
Yellow WarblerOP
Hello, I have a seperate frontend (next) and backend (express).
In development, CORS errors were not an issue
However, after running in docker containers (I also changed the backend API host to
So naturally I was like "oh ill just add it to my CORS origin" and it did nothing
In development, CORS errors were not an issue
app.use(cors({ origin: "http://127.0.0.1:3000", credentials: true, allowedHeaders: ["Content-Type", "Cookie", "Accept", "Origin", "Authorization"], methods: ["PUT", "GET", "POST", "PATCH", "DELETE", "OPTIONS"] }))However, after running in docker containers (I also changed the backend API host to
host.docker.internal, I started getting this errorCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://host.docker.internal:8080/logout. (Reason: CORS request did not succeed). Status code: (null).So naturally I was like "oh ill just add it to my CORS origin" and it did nothing
7 Replies
bit weird. host.docker.internal is to access from container(docker) to host(mac/win). your browser runs on host(mac/win) or are you running a browser inside container?
CORS itself has nothing to do with Next.js server. it prevents a web browser(chrome/safari) to load resources downloaded from non-same origin(cross origin).
@tafutada777 bit weird. host.docker.internal is to access from container(docker) to host(mac/win). your browser runs on host(mac/win) or are you running a browser inside container?
Yellow WarblerOP
that’s exactly correct. I am not running a browser inside a container though
actually i also was able to identify that it only happens with POST requests
GET requests work fine
â‰ï¸idk how that is happening