Search code examples
angularjspreflightsatellizer

Satellizer causes Angular to pre-flight ALL of my rest queries with an OPTIONS request


If all servers responded to an OPTIONS request this would not be a problem, but Satellizer even causes Angular to pre-flight a GET request with Content-Type text/plain. In effect, it breaks half of my other REST queries.


Solution

  • After looking through the code and studying Angualr's httpProvider I realized that Sateliizer is intercepting every single request using httpProvider's interceptors array and adding the following:

    var token = localStorage.getItem(tokenName);
    if (token && config.httpInterceptor) {
      token = config.authHeader === 'Authorization' ? 'Bearer ' + token : token;
      httpConfig.headers[config.authHeader] = token;
    }
    

    So that every single request gets an Authorization header. Since I actually have only ONE request that needs an authorization header I modified the conditional statement:

    if (token && config.httpInterceptor && httpConfig.auth===true) {
    

    and then in my $http.get for the single service that actually needs authorization I add:

            var config = {auth: true};
            $http.get(googleUrl, config)