r/webdev • u/Mob_Pilled • 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
3
u/torn-ainbow Oct 24 '26
2
u/jjangg96 Oct 24 '26
besides adding headers, check one thing first. that url with the hash and your team name in it is a per-deployment url, and vercel puts those behind deployment protection by default. when it's on, the request gets vercel's login page back as a 401 and that response has no cors headers, so the browser shows exactly this cors error even if your code is fine.
open the server url directly in a private window. if you get a vercel login page that's it, turn it off under the project's deployment protection settings or call the production domain instead.
if it loads fine then it is the headers. set access-control-allow-origin to your client's origin and answer the OPTIONS preflight too. if the server is express, the cors package does both.
1
u/Mob_Pilled Oct 24 '26
After two hours of fighting with cors I finally found the issue and got it to work. Thanks guys! (For anyone coming here in the future, carefully read the warning message in the console. Specifically take note of what url address it says is permitted by "access-control-allow-origin". If it is not your vercel url, you probably need to change the origins header of the object passed into cors)
1
u/tjthouhid1 Oct 25 '26
Two things jump out from that error. First, both URLs are preview deployment URLs (the ones with the random hash), and they change on every deploy, so any origin you hard-code goes stale. Use the stable production domains for both projects, and put the API URL in an env var on the client. Second, your server has to send the CORS header itself. In Express that's
app.use(cors({ origin: process.env.CLIENT_ORIGIN }))from thecorspackage, set before your routes. One sneaky Vercel gotcha: preview deployments often have Deployment Protection on, so the request gets bounced to a Vercel login page that has no CORS headers, and it shows up as exactly this error. Try hitting the server URL directly in an incognito window. If you see a Vercel login, that's your problem. Also,ipAddress=is empty in that request, so check that too once CORS is fixed.0
u/[deleted] Oct 24 '26
[removed] — view removed comment