axios options请求后台跨域配置

app.all('*', function (req, res, next) {
         res.set('Access-Control-Allow-Origin', '*');
         res.set('Access-Control-Allow-Credentials', true);
         res.set('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT ,OPTIONS');
         res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Authorization'); 
         res.header("Content-Type", "application/json;charset=utf-8");
    if (req.method.toLowerCase() == 'options')
          res.send(200); //让options尝试请求快速结束
     else
         next();
 });

猜你喜欢

转载自www.cnblogs.com/qiyc/p/11098930.html
今日推荐