Cross-Origin Request Blocked with React and Express

前端 未结 4 1228
长情又很酷
长情又很酷 2021-01-12 15:54

So I hit this error, when I was trying to send data to the back end using React. From what I learnt I need to allow the communication on the back-end and in the .htacc

4条回答
  •  甜味超标
    2021-01-12 16:09

    There's a node package called cors which makes it very easy.

    $npm install cors

    const cors = require('cors')
    
    app.use(cors())
    

    You don't need any config to allow all.

    See the Github repo for more info: https://github.com/expressjs/cors

提交回复
热议问题