r/webdev • • Oct 24 '26

Question Vercel client can't communicate with server

Hello everyone. I have been developing a simple ip tracking full stack app. When I deployed the client project to vercel however it fails to communicate with the server and fetch data. In the console this error is visible:

ccess to fetch at 'https://ip-tracker-server-*********-webs-projects.vercel.app/api?&ipAddress=' from origin 'https://ip-tracker-client-********-webs-projects.vercel.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

This is my first time deploying a full-stack app to vercel so I am not sure what exactly could be causing this issue? If anyone could help it would be much appreciated!

0 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/Mob_Pilled Oct 24 '26

Other than "origin" what other headers are supposed to be included in the cors options object to gurantee it working? is preflight supposed to be set to true or false? I only have the origin property as of now and it points to my (domain not deployment) url

1

u/nabhan_builds Oct 24 '26

You don't need a long list of headers. For a normal fetch like yours, origin is the main one, and this is enough in Express:

app.use(cors({ origin: 'https://your-client-domain', methods: ['GET', 'POST'], allowedHeaders: ['Content-Type', 'Authorization'], }));

Only add allowedHeaders for headers you actually send. If you only send a plain GET with no Authorization or custom header, you don't even need that line.

On preflight: leave preflightContinue false, which is the default. That means the cors middleware answers the OPTIONS request itself. If you set it to true, it passes OPTIONS on to your routes, which usually don't handle it, so it fails. Don't set it to true unless you are handling OPTIONS yourself.

Two things that still break this even with the right config:

  1. origin has to match exactly what the browser shows, including https and no trailing slash. If you open the deployment URL in the browser but only allow the production domain, it will still be blocked. Allow the exact origin you are actually visiting, or use an array with both.
  2. Redeploy the server after changing this. Changing the code alone doesn't update the live deployment.

Don't use origin: '*' if you ever add cookies or auth headers, it won't work with credentials.

1

u/jjangg96 Oct 26 '26

if you're using the cors package then origin is basically all you need. it answers the preflight on its own by default and it reflects whatever headers the browser asks for, so there's no preflight true/false to set. credentials: true only matters if you send cookies.

the part i'd check is the exact match though. the error you pasted says the request came from the per-deployment client url with the hash in it, not your domain. if the browser loaded the page from that url and your origin is set to the custom domain, they don't match and you get this same error. open the client the way a user would, from the domain, and see if it goes away.

also no trailing slash in the origin string, it has to match character for character.