Reputation: 101
I am getting this error
(index):1 Access to XMLHttpRequest at 'https://example.com/crm/addlead' from origin 'https://abc.examplehosting.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
i have added this code as well in my app.js
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();
});
Please suggest what could be the issue.
Upvotes: 1
Views: 151
Reputation: 1722
You need to install cors
CORS.
const cors = require('cors')
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200 // some legacy browsers like IE11
}
app.use(cors(corsOptions));
Upvotes: 2
Reputation: 1739
Try adding cors
layer to your app,
npm install --save cors
// In your server file
var cors = require('cors');
...
app.use(cors());
Find out more details on cors here
Upvotes: 1