Set CORS on Express API

来源:互联网 发布:51单片机 多任务 编辑:程序博客网 时间:2024/05/22 16:05

http://stackoverflow.com/a/21622564/2177408


I found the easiest way is to use the node.js package cors. The simplest usage is:

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

There are, of course many ways to configure the behaviour to your needs; the page linked above shows a number of examples.

You need to also set cors({credentials: true, origin: true})

When origin is set to false, means disabling the CORS. 

0 0