How to allow CORS in react.js?

后端 未结 8 1615
[愿得一人]
[愿得一人] 2020-12-25 12:11

I\'m using Reactjs and using API through AJAX in javascript. How can we resolve this issue? Previously I used CORS tools, but now I need to enable CORS.

8条回答
  •  旧时难觅i
    2020-12-25 12:31

    It is better to add CORS enabling code on Server Side. To enable CORS in NodeJS and ExpressJs based application following code should be included-

    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();
    });
    

提交回复
热议问题