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();
 });

posted @ 2019-06-27 18:42  江山一族  阅读(1868)  评论(1编辑  收藏  举报