Just2Click
Just2Click

Reputation: 545

Ember App Kit CORS

I'm using Ember App Kit trying to build an application that logs into an existing server. My problem is that I'm getting the following message:

XMLHttpRequest cannot load https://example.server.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. 

I've Googled this around and it seems that I need to add/enable CORS in my express-server. I've tried following various samples, such as:

  1. https://www.npmjs.org/package/cors
  2. https://github.com/troygoode/node-cors
  3. http://bannockburn.io/2013/09/cross-origin-resource-sharing-cors-with-a-node-js-express-js-and-sencha-touch-app/

But I couldn't get it to run.

In short I'm trying to find a sample of how should I add the CORS onto my express-server

Cheers,

Dror

Upvotes: 0

Views: 521

Answers (2)

Just2Click
Just2Click

Reputation: 545

Eventually I dodged the bullet by using an already running server to serve my ember project.

Thank you kiwiupover and ulisesrmzroche for a timely response

Upvotes: 0

ulisesrmzroche
ulisesrmzroche

Reputation: 145

Stick this inside your Em.Application.extend, inside the ready hook

$(document).ajaxSend(function (event, xhr, settings) {
  settings.xhrFields = {
    withCredentials: true
  };
});

For express, try using the cors module on npm. https://www.npmjs.org/package/cors. It should all work out of the box.

Upvotes: 1

Related Questions