I have no clue why this piece of code prevents my API from working properly. It causes all requests to process endlessly and if I remove it - everything works fine
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE");
});
There's no call to next()
so the request gets hung up here. It doesn't advance to other request handlers (that's what next()
does) and it doesn't send a response so the request just dies there and will probably eventually timeout. Add next()
like this:
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE");
next();
});