Next.js Discord

Discord Forum

Blocked By CORS

Unanswered
Australian Freshwater Crocodile posted this in #help-forum
Open in Discord
Avatar
Australian Freshwater CrocodileOP
Hello!

Im trying to make a request to my Node API from a Next.js app. In my API I check the origin of the request and then block any requests from origins that are not approved.

For some reason the origin for requests coming from the Next.js app are undefined.

Any ideas on how to fix this?

11 Replies

Avatar
Madeiran sardinella
i think this is more of a Node issue than Next
one way you can debug is try hosting your app on say Vercel, and then add that url's origin to your cors middleware and see if it works
Avatar
Australian Freshwater CrocodileOP
It works fine with my other react app that is hosted on vercel is the thing
Also this current one is also on vercel so not sure why the origin would be missing
Unless it has something to do with me sending the request from a SSR component?
Avatar
Madeiran sardinella
what error are you getting?
Avatar
Madeiran sardinella
and how are you fetching your data inside your SSR component?
Avatar
tafutada777
i guess it is NAT stuff. server side codes run on AWS lambda or Cloudflare worker. The former is serverless, dynamic instances. thus it is impossible to have a fixed global ip (unless AWS lambada in VPN). as for CF, the edge servers are scatterd across countries, so it is impossible to have IP filter or CIDR even if it has a fixed global ip. my hunch. not sure. Vercel might have an NAT option for enterprise customers.
so in general, the upstream endpoint is something like ep-luck-boat-3746763-pooler.us-east-1 , long host name with random words with an API key. in general.
when invoking from useeffect() , you get an customer VPN IP obviously.
this is my hunch. not sure btw