Support Forums

Netlify functions:serve cors issue

I am trying to use “netlify functions: serve” due to the issue I’m having with netlify dev explained here:

But I’m getting the expected cors issue because the functions are in a different port. I can’t serve them on the same port as my react app either (3000). How does netlify dev make it so that you can call them on the same port?

How do I do this with “netlify functions: serve”? Or do I need to use the access control header? How can I do that only on development?

Hi @ShaCP,

You can’t run functions on the same port as React as React consumes that port and thus, Netlify CLI won’t be able to use it. You’d have to use Access Control headers. You could simply comment/uncomment the Access Control headers when testing locally and deploying online.

Without that, you could set an environment variable and check if that variable exists to set the required headers.