1

Following Restangular's documentation and includes an example of this:

// GET to http://www.google.com/ You set the URL in this case
Restangular.allUrl('googlers', 'http://www.google.com/').getList();

I am trying to do the same for angel.co

$scope.trial = Restangular.allUrl('googlers', 'https://api.angel.co/1/users/267770').getList();

And keep getting error

XMLHttpRequest cannot load https://api.angel.co/1/users/267770. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. 

Any solutions?

Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84

1 Answers1

2

The server (api.angel.co) is not responding with Access-Control headers which results in this error.

When sending XHR requests to domains different from the origin domain web browsers are checking if the service allows this. In your case api.angel.co would need to include the header Access-Control-Allow-Origin: * as part of the response (which it does not).

Assuming you cannot change api.angel.co, an alternative would be to build a server-side proxy (e.g. in node.js) which allows Cross-Origin Resource Sharing.

Check out this great article about Cross-Origin Resource Sharing (CORS).

Sebastian
  • 16,813
  • 4
  • 49
  • 56
  • Thanks @Sebastian for the answer. This may sound really dumb, but I am using the Angular-seed repo (https://github.com/angular/angular-seed), and running on a localhost:8000. Would that be a Node.js server? And what happens when it's in production? – Mohamed El Mahallawy Apr 15 '14 at 15:28
  • Angular is a client side framework which runs in the browser. The proposed node.js proxy would be a completely separate component to enable you to access the API. It would work as follows: The browser (which is running your Angular app) sends the API request to the to-be-developed node.js component (which allows CORS or runs on the same host). This component will then proxy the request to the actual API at api.angel.io. – Sebastian Apr 15 '14 at 15:36
  • Yes, I understand. But with angular-seed I am running on a node.js server no? I have all the web-server files, etc. So where can I plug in code to allow for CORS? – Mohamed El Mahallawy Apr 15 '14 at 15:38
  • eg. http://stackoverflow.com/questions/20036008/angular-seed-web-script-js-and-cors but didn't find the same code – Mohamed El Mahallawy Apr 15 '14 at 15:38
  • Check [this](http://stackoverflow.com/questions/7545328/proxy-with-nodejs). You should develop it as a separate component and not bundle it with the Angular Seed test web server. – Sebastian Apr 15 '14 at 15:48