I have a code that is utilizing CORS to get stuff like fonts, images, etc. but someone on my team modified the code and all petitions utilizing fetch()
stopped working. Here’s how it looks:
app.use(cors({
origin: function (origin, callback) {
if (!origin) return callback(null, true);
if (whiteList.indexOf(origin) === -1) {
var msg = 'Acceso Denied.';
return callback(new Error(msg), false);
}
return callback(null, true);
}
}));
I solved the issue by simply commenting this declaration of CORS and instead just did app.use(cors());
.
I didn’t write this code, so although the issue was solved I’d like to know what was causing the petitions to stop working and/or what’s wrong with the function on the origin property.
Any insight is appreciated 🙂