0

Getting No 'Access-Control-Allow-Origin' header is present on the requested resource when trying to access my node express web service from my ember application.

I have a node web service project running on http://localhost:3000

And my ember application project running on http://localhost:63342

When I try to connect to my server and request customer (http://localhost:3000/customers) I get:

XMLHttpRequest cannot load http://localhost:3000/customers. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. 

I assume I need to do something on the rest adapter to allow this? Or is there are way to have both projects listening in the same port? Which would be the best way?

Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60
camba1
  • 1,795
  • 2
  • 12
  • 18
  • https://www.npmjs.org/package/cors – vkurchatkin May 13 '14 at 17:34
  • 1
    Try searching on Cross Origin Resource Sharing for Express. You need to setup express to allow the ember application to access your REST service since they are on different ports. Here's one thread I found:http://stackoverflow.com/questions/11181546/node-js-express-cross-domain-scripting – Sarus May 14 '14 at 00:24
  • Thanks vkurchatkin and Sarus!! I enabled CORS for express and now it works as a charm. – camba1 May 14 '14 at 23:01
  • Hi camba1 could you post how did you enable cors with ember? I am using ember cli. – Moh Mar 27 '15 at 19:28

1 Answers1

0

A very old question. But just in case someone it still looking for an answer.

You will need to configure CORS on the server side (not client). The easiest way I know is to use an npm package cors

npm install cors --save

and then add it as middleware in your express app

const cors = require('cors');
const express = require('express');
const app = express();
app.use(cors());

Check npm page for more info on how to configure cors for your specific needs.

bentesha
  • 898
  • 9
  • 14