Next.js Discord

Discord Forum

How to configure CORS headers without using nextjs backend?

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Hey folks,

we are using nextjs for our frontend application because of some ssr stuff, routing and some legacy decisions.
Now I want to use our own backend without routing the request through the nextjs server.
The routing through the nextjs server could be a problem later because of scaling.

But I've now a problem because the cors configuration permits requests to (currently) localhost:8080 .
:3000/de:1 Access to XMLHttpRequest at 'http://127.0.0.1:8080/api/positions?filters[conditions][0][0]=status&filters[conditions][0][1]=Equals&filters[conditions][0][2]=New' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Is there a easy way to fix that?
I just found some solutions routing through the nextjs backend.

T
Answered by Sun bear
But Thank you, you are right. The problem was on the backend site.
Currently I fixed it by allowing all origins. Later I will replace it with the specific domain the frontend uses
View full answer

4 Replies