Access to fetch at 'https://blessed-clothing-9pvjilzza-supergemheres-projects.vercel.app/products?page=1&limit=10&sort=asc&maxPrice=1000&gender=&age=&trending=false&sale=false' from origin 'https://foot-gear-e-store.vercel.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
This is my vercel.json : { "version": 2, "rewrites": [{ "source": "/(.*)", "destination": "/api" }] }
Can someone please help me out with this headache…
Hi @supergemhere. Did you add the headers in your Express configuration? It’s best to use the framework’s preferred strategy when one is provided since this prevents configuration conflicts.
Some people have found that Express CORS Middleware makes configuration easier. But there are many ways to configure your app.
I found some more resources that may help you get it working in your project:
It’s also worth reading to understand more about CORS if you’re not already familiar. These pages can help you understand how it works so you can identify what’s going wrong.
Yes, I’m using the CORS lib from node and I managed it to work, actually everything was fine on local environment, the problem happens on the deployed version on the vercel, It kinda looks like it doesn’t care about the CORS options written inside the index.js file, also I have read an article where there was said that vercel somehow overwrites the CORS.
Vercel respects the CORS headers you set in your application. If you’ve configured CORS headers in your code or in the vercel.json config, these will be preserved. There are some other headers that automatically get added to deployments, such as x-vercel-id, x-forwarded-host, and x-robots-tag. That may have the source of confusion for whoever wrote the article you found.
The preferred method is to set headers in your application code. But it’s also possible to add headers in a vercel.json for the project. There’s a guide listing the options and some examples here: