Express 跨域设置

2018-01-11  本文已影响0人  大地母亲忽悠着你
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header("Access-Control-Allow-Headers",
  "Content-Type,Content-Length, Authorization, Accept,X-Requested-With,Access-Control-Allow-Origin");
if (req.method === 'OPTIONS') {
  res.sendStatus(200)
}else{
  next()
  }
})
上一篇 下一篇

猜你喜欢

热点阅读