Reputation: 769
I am trying to set up local development environment of Angular.js app which gets data from a remote API, but I am stuck with cross-domain origin policy. The API is not serving JSONP or anything except pure JSON response. Although, GET works correctly on my website. Is there any other solution than moving dev environment to the remote server (or if it even help, to move it)?
Upvotes: 0
Views: 456
Reputation: 11568
Yes your other option is to setup CORS on the server and set your angular js app to consume xDomain services.
Setting up a server to enable CORS is easy using few response headers which needs to be sent for each call:
You can find out about enabling them based on your server technology here:
http://enable-cors.org/server.html
and as for angularjs you need to setup xDomain calls in the config section of app.js:
.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
})
Upvotes: 1