You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey,
Try this , cause I think u must pass a function rather than an array
var allowedOrigins = ['http://localhost:3000',
'http://yourapp.com'];
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);
}
}));
@KaidiMohammed This is working if we use callback function but it return Access-Control-Allow-Origin: * instead of Access-Control-Allow-Origin: http://domainname.com in request header.
I'm trying to add cors to express app right after setting it,
expected behaviour is it should allow requests from 'some_origin' and 'some_origin_2' but instead both are still blocked.
The text was updated successfully, but these errors were encountered: