How to Enable CORS from Nodejs server

前端 未结 3 1598
感动是毒
感动是毒 2021-01-22 21:19

I am using react to send data to my API. Every POST request I make gives me an OPTIONS request, and I need to fix this. I think I might need to do some preflight structure but a

3条回答
  •  梦谈多话
    2021-01-22 21:57

    If you are using Express.js just install cors:

    npm install cors
    

    Then you add it like this:

    var express = require('express')
    var cors = require('cors')
    var app = express()
    
    app.use(cors())
    

提交回复
热议问题