This is how I'm implementing CORS on my backend
const allowedOrigins = ['http://localhost:3000', 'https://(myvercelapplink).app'];
app.options('*', cors());
app.use(cors({
origin: function(origin, callback){
// allow requests with no origin (like mobile apps or curl requests)
if(!origin) return callback(null, true);
if(allowedOrigins.indexOf(origin) === -1){
var msg = 'The CORS policy for this site does not allow access from the specified Origin.';
return callback(new Error(msg), false);
}
return callback(null, true);
},
credentials: true
}));
This is my vercel.json file in frontend. I have used rewrite because I'm using react router.
{
"rewrites": [
{"source": "/(.*)",
"destination": "https://(mybackendlink).com"
}
]
}
I'm trying to login using google & after a successful login, I run an api called user-details which fetches my user data to the frontend.
But the request is 'pending' when I run it on Vercel, but it works fine on localhost. networks screenshot