How to allow CORS in react.js?

后端 未结 8 1568
[愿得一人]
[愿得一人] 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条回答
  •  囚心锁ツ
    2020-12-25 12:28

    Use this.

    app.use((req,res, next)=>{
        res.setHeader('Access-Control-Allow-Origin',"http://localhost:3000");
        res.setHeader('Access-Control-Allow-Headers',"*");
        res.header('Access-Control-Allow-Credentials', true);
        next();
    });
    

提交回复
热议问题