Some time while working on HTTP get or post a request from another application you will get CORS blocked by HTTP and you will not be able to send a request to the server.
CORS - Cross-Domain Requests.
Simply send the below header to your request to enable CORS.
res.header("Access-Control-Allow-Origin", "*");
If you want to enable all the requests on the server.
In your app.js file, you can put below code snippet.
var express = require('express');
var app = express();
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();
});
I had a look at the details that you mentioned in the content regarding Enable CORS in node js and I believe that the content mentioned in the blog is very description and knowledgeable. I must recommend everyone to read this.
ReplyDeleteI was searching for Node js development company and found your blog.
Synsoft Global
Thanks for sharing such a great blog.