AngularJS: $http interceptor change every call method to OPTIONS

后端 未结 1 385
無奈伤痛
無奈伤痛 2021-01-22 13:33

So, I\'m trying to intercept the http calls to add the Authorization header on each call if exist. This works well exept of the fact that no matter which http method I use (GET,

相关标签:
1条回答
  • 2021-01-22 14:09

    When you implement your own interceptor on Front-End side, you should remember about CORS:

    app.use(function(req, res, next) {
        res.header('Access-Control-Allow-Origin', req.headers.origin || "*");
        res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,HEAD,DELETE,OPTIONS');
        res.header('Access-Control-Allow-Headers', 'content-Type,x-requested-with,authorization123456,accept');
        next();
    });
    

    We should remember to set Acces-Controll-Allow on Methods as well as on Headers. In my case it's 'authorization123456' where I put my token which is added to every request from AngularJS.

    0 讨论(0)
提交回复
热议问题