1. 跨域

app.all("*", function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "content-type,Authorization");  // Authorization为你添加的请求头中的字段如(headers:{ "Authorization" : "ssss"});注意!不能用*号,否则safari和火狐不认识
  res.header("Access-Control-Allow-Methods", "DELETE,PUT,POST,GET,OPTIONS");
  if (req.method.toLowerCase() == 'options') {
    res.send(200);
  } else {
    next();
  }
});

posted @ 2019-01-14 15:12  大耳朵小虎  阅读(92)  评论(0编辑  收藏  举报