I have an express.ts (typescript) backend.
When I test an endpoint locally, ‘Access-Control-Allow-Origin’ header is present.
When I deploy it on Vercel, I get the error:
No ‘Access-Control-Allow-Origin’ header is present on the requested resource
I have no idea why, and I am completely blocked on that, I did:
const corsOptions = {
origin: config.frontEndUrl, // I checked that is correct on vercel
credentials: true, // access-control-allow-credentials:true
optionSuccessStatus: 200,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
allowedHeaders: "Content-Type, Authorization",
};
app.use(cors(corsOptions));
Here Here is my repo.
Here is my vercel.json
:
{
"version": 2,
"builds": [
{
"src": "dist/index.js",
"use": "@vercel/node",
"config": { "includeFiles": ["dist/**"] }
}
],
"rewrites": [{ "source": "/(.*)", "destination": "/api" }]
}