This probably may be a duplicate question, but I'm not able to do this correctly.
I have enabled CORS in my backend (reading this). But, still, when I try to hit an API on my API server through my UI server, I get this:
Request header field Authentication is not allowed by Access-Control-Allow-Headers in preflight response.
Here are some relevant parts of my code:
Backend
// enable CORS
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Frontend
$.ajax({
method: 'GET',
url: ...,
headers: {
Authentication: ...
},
...
});