I have build the api server with nodeJS and Express
Then I enabled CORS with the package CORS
import cors from "cors";
const app = express();
app.use(
cors({
origin: "*",
})
);
Vercel configuration:
{
"version": 2,
"builds": [
{
"src": "./index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "./index.js"
}
]
}
However, I always have the CORS error when access to the API server on vercel.
Access to XMLHttpRequest at 'https://apiurl/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I was testing on my local with setting enable CORS. There is problem with the snippet code above.
Please point me out what is something wrong here.
Thank you