Search code examples
angularjscross-domainangularjs-service

Is there a way to avoid Preflighting with $http?


I'm using nginx on the remote server, and with no support for the OPTIONS method I've been terribly stuck. Both the server and angular refuse to talk to each other.

I just want to make a simple $http.post() request. Is there a way to configure the service to ONLY send the POST request, and not do any preflighting with OPTIONS?


Solution

  • This is not something AngularJS does, but something your browser does according to the Cross-Origin Resource Sharing standard. See also this answer on a related issue.

    However, if you make it so that the AngularJS application is served from the same domain as your resource (different subdomains will affect cross-origin), then the browser will not send the OPTIONS request as the resource is no longer from a cross-origin server.

    Example:

    • www.example.com requests resource on api.example.com will trigger OPTIONS request
    • www.example.com requests resource from www.example.com/api will not trigger OPTIONS request