How to allow CORS in react.js?

后端 未结 8 1612
[愿得一人]
[愿得一人] 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:43

    on the server side in node.js I just added this and it worked. reactjs front end on my local machine can access api backend hosted on azure:

    // Enables CORS
    const cors = require('cors');
    app.use(cors({ origin: true }));
    

提交回复
热议问题