node.js习题(设置允许跨域访问服务)

// 设置允许跨域访问该服务
app.all('*', function (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', 'X-Requested-With');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  next();
});

猜你喜欢

转载自blog.csdn.net/weixin_46611729/article/details/110038349