在app.js的最开始加上

app.all('*', (req, res, next) => {
    res.header("Access-Control-Allow-Origin", req.headers.origin || '*');
    res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("Access-Control-Allow-Credentials", true); // 可以带cookies
    if(req.method == 'OPTIONS') {
        res.sendStatus(200);
    } else {
        next();
    }
});

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-13
  • 2021-10-03
  • 2022-12-23
  • 2021-05-29
  • 2021-05-28
  • 2022-01-12
猜你喜欢
  • 2021-04-19
  • 2022-12-23
  • 2021-10-31
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
相关资源
相似解决方案