lundi 2 janvier 2017

Work around CORS Ember error for a Rails backend

Building a front end interface using a Rails REST API, I get the error

XMLHttpRequest cannot load http://ift.tt/2hFpgbu
No 'Access-Control-Allow-Origin' header is present on the requested 
resource. Origin 'http://localhost:4200' is therefore not allowed access.

I've set up my adapter to be

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  namespace: 'api/v1',
  host: 'http://www.example.com'
});

If I was building the API, I would just include the gem 'rack-cors' and allow for the access to other sites. I'm just starting out with the Ember framework and haven't yet found a work around for this.

I've tried running a proxy server

ember s --proxy http://www.example.com

But I get the same response. Is there a piece of middleware or a method on the RESTAdapter that I can use to bypass this error?




Aucun commentaire:

Enregistrer un commentaire