Home Ask Login Register

Developers Planet

Your answer is one click away!

Wolf87 February 2016

Cross-Origin Request Blocked - NodeJs

I'm having an issue with my MEAN stack app on the AWS - Windows. So, I've placed a port 3000 for Node server to listen, and IIS is using port 80 by default.

Then when I start the node server to listen, and fire the app I want to GET some data with Angular through Node. I'm trying with this:

$http.get('http://localhost:3000/get_data').success(function(response) { // something with response });

This reproduce an error in my console:

enter image description here

This is a blocker for me, I would really appreciate if someone can point me to the right way.

I'm also interested to know why this is happening, why I'm getting CORS with port different then default (80)?



Bibek Subedi February 2016

There is a nice node.js package called cors. You can make use of this library in following way

var cors = require('cors')
app.options('/get_data', cors());
app.route('/get_data').get(cors(), doOperation());

ashfaq.p February 2016

You can enable Cross origin request at node side by using CORS module. Read more about the module and documentation here: Enable cors

var cors = require('cors');

Post Status

Asked in February 2016
Viewed 2,393 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life