Right not i’m working on MEAN stack application.
On the API project i am using CORS plugin with following options
const corsWhitelist = [
"http://localhost:9200"
];
const corsOptions: any = {
origin: function (origin: string, callback: any) {
switch (process.env.ENV_MODE) {
case EnvironmentMode.dev:
case EnvironmentMode.test:
callback(null, true);
break;
case EnvironmentMode.prod:
if (corsWhitelist.indexOf(origin) !== -1) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
break;
}
},
credentials: true,
methods: ["GET", "POST", "PATCH", "DELETE"],
};
app.use(cors(corsOptions));
The thing is, it was working fine until yesterday. I was able to make request from angular app and postman. I didn’t changed any code in API project, was just modifying angular app.
Now my front end app throws following error
https://i.stack.imgur.com/MxOzY.jpg
but postman still works fine
Then i tried to rollback my both angular and api projects to 3 days ago (when everything was fine), but this problem didn’t gone. I think there is something happened with CORS package itself or it’s dependencies.
What can you suggest?
Source: Angular Questions
One Reply to “node.js CORS package suddenly stopped working”
Hi, did you solve this? The same is happening to me now!