NODEJS “CORS Errors”

NodeJS can be configured to use CORS as means of communicating from the front-end. This can be configured in your app.js as middleware for the popular Express package.
CORS errors look something like this:

Cors-error

Both servers are running on different ports. Remember that different port consists as a cross domain request. localhost:8080 is a different domain to localhost:9000 (it’s everything before the forward slash). Node running on port 8080Angular running on port 9000You need to include your CORS enabler before your middleware or app.send requests.

You can either include the following code or include an express middleware package to do this for you, such as npm install CORS.

// Enable CORS
app.use(function( req, res, next ) {
res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header("Access-Control-Allow-Headers", "x-requested-with, content-type");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Max-Age", "1000000000");
// intercept OPTIONS method if ('OPTIONS' == req.method) { res.send(200); } else { next(); } });

Setting the domain in the Angular Seed

You may need to set the domain in the Angular seed go to /app/scripts/config.js Change this line:

$httpOptionsProvider.setDomain('http://localhost:8080');

To this:

$httpOptionsProvider.setDomain('http://162.243.69.108:8080');

Where the IP address can be your domain name.

Refs:
http://stackoverflow.com/questions/6809459/how-to-run-node-js-from-my-computer
http://enable-cors.org/server_expressjs.htmlhttp://client.cors-api.appspot.com/
https://npmjs.org/package/cors