Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS request to remote Sails server

I'm trying to make a request to a remote server running with Sails JS (NodeJS) using AngularJS in the frontend and I'm getting this origin 'null' error:

XMLHttpRequest cannot load http://remoteserver:1337/login/. The 'Access-Control-Allow-Origin' header contains the invalid value ''. Origin 'null' is therefore not allowed access.

My request looks somethign like:

$http.post('http://remoteserver:1337/login/', { email: userData.email, password: userData.password}); 

Any ideas?

like image 687
Agustín Avatar asked Jul 22 '26 06:07

Agustín


1 Answers

You nead the server to enable CORS (cross origin resource sharing),

from Sails.js cors documentation (http://sailsjs.org/documentation/concepts/security/cors)

To allow cross-origin requests from any domain to any route in your app, simply enable allRoutes in config/cors.js: allRoutes: true

and here is a brief explanation about what CORS is and why it is needed:

http://enable-cors.org/index.html

like image 193
MoLow Avatar answered Jul 24 '26 23:07

MoLow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!