First at all, I have researched about the topic after writing the question, there are many similar question but I think the problem here is different:
No 'Access-Control-Allow-Origin' - Node / Apache Port Issue
We are getting this Access-Control-Allow-Origin cors error just when we send a heavy request:
Access to XMLHttpRequest at 'https://backend.*****.es/xxxxxx' from origin 'https://www.testing.*******.es' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
The rest of the request are working fine, I tried setting:
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
but I got the same error.
I am starting to think it can be related with nginx.
This is the architecture we are using:
- NodeJs, Expressjs
Middlewares:
const LIMIT = '100mb'; const global = () => [ morganMiddleware(), compression(), cors(), bodyParser.urlencoded({ extended: true, limit: LIMIT }), bodyParser.json({ limit: LIMIT }), helmet(), ];
Server: Nginx 12.14.1
Host in AWS Elastic BeanStalk
Let me know if anyone have any clue what can be happening because I do not know if it is coming from our nodejs server, or nginx. We have tested many solutions and are still checking out other options.