美文网首页
nodejs的跨域请求

nodejs的跨域请求

作者: 放风筝的小小马 | 来源:发表于2018-01-27 22:51 被阅读21次
app.all('*', (req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With');
  res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT, OPTIONS');
  res.header('X-Powered-By', ' 3.2.1');
  if (req.method === 'OPTIONS') {
    res.sendStatus(200);
  } else {
    next();
  }
});

相关文章

网友评论

      本文标题:nodejs的跨域请求

      本文链接:https://www.haomeiwen.com/subject/uptoaxtx.html