Im trying to get a text/html of an url differnt from origin, but i cant get a POST because a CORS block.
Im makeing the requisition in angular this way:
const express = require('express');
const cors = require('cors');
validateOperador(login,pass){
const url = `${this.operadoresValidateUrl}a=${login}&b=${pass}`
return this.http.get(url,{headers:
{'Content-Type': 'text/html', 'Access-Control-Allow-Origin': '*' } })
}
and my node backend using express, is configured this way:
app.use(function (req, res, next) {
//Enabling CORS
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
res.header("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, x-client-key, x-client-token, x-client-secret, Authorization");
next();
});
httpServer = http.createServer(app);
app.use(cors())
app.use(bodyParser.json())
app.use(compression());
Im getting this error:
Access to XMLHttpRequest at 'my api url' from origin 'my project url' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is not a duplicated question, because I´ve already installed and runned CORS