Origin <origin> is not allowed by Access-Control-Allow-Origin Origin <origin> is not allowed by Access-Control-Allow-Origin google-chrome google-chrome

Origin <origin> is not allowed by Access-Control-Allow-Origin


Since they are running on different ports, they are different JavaScript origin. It doesn't matter that they are on the same machine/hostname.

You need to enable CORS on the server (localhost:8080). Check out this site: http://enable-cors.org/

All you need to do is add an HTTP header to the server:

Access-Control-Allow-Origin: http://localhost:3000

Or, for simplicity:

Access-Control-Allow-Origin: *

Thought don't use "*" if your server is trying to set cookie and you use withCredentials = true

when responding to a credentialed request, server must specify a domain, and cannot use wild carding.

You can read more about withCredentials here


If you need a quick work around in Chrome for ajax requests, this chrome plugin automatically allows you to access any site from any source by adding the proper response header

Chrome Extension Allow-Control-Allow-Origin: *


You have to enable CORS to solve this

if your app is created with simple node.js

set it in your response headers like

var http = require('http');http.createServer(function (request, response) {response.writeHead(200, {    'Content-Type': 'text/plain',    'Access-Control-Allow-Origin' : '*',    'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE'});response.end('Hello World\n');}).listen(3000);

if your app is created with express framework

use a CORS middleware like

var allowCrossDomain = function(req, res, next) {    res.header('Access-Control-Allow-Origin', "*");    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');    res.header('Access-Control-Allow-Headers', 'Content-Type');    next();}

and apply via

app.configure(function() {    app.use(allowCrossDomain);    //some other code});    

Here are two reference links

  1. how-to-allow-cors-in-express-nodejs
  2. diving-into-node-js-very-first-app #see the Ajax section