javascript - AngularJS CORS issue in Chrome - No 'Access-Control-Allow-Origin' header is present on the requested resource -


i'm doing little exercise familiarise myself angularjs , have app running on http://127.0.0.1:9000/ after execute necessary grunt task. wish write/teach myself how allow authorization/authentication request (basically login form). have seperate project has rest api, running on http://127.0.0.1:3000/ - notice difference in port numbers. exercise hosted on local machine wish use cors requests browser restrictions aren't issue , app own amusement. in angularjs app have included following code in config allow cors requests:

// set cors... $httpprovider.defaults.usexdomain = true; delete $httpprovider.defaults.headers.common['x-requested-with']; 

in rest api / node project include cors middleware available https://www.npmjs.org/package/cors , have enabled cors requests, have included library so:

cors = require('cors') 

and then...

app.use(cors()); // in app.configure 

when test api using websore rest tool data desire retured when trying access angularjs app chrome javascript console gives me following error:

no 'access-control-allow-origin' header present on requested resource 

is there have missed setting cors angularjs? in advance.

phew, seem have fixed in... in app needed put requirements in following order:

app.use(cors()); app.use(app.router); 

the app.use(cors()); must come before app.use(app.router);


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -