2

Has anyone had success working with a front-end only applications with Ember.js and consuming endpoints from an external host? If so please share your experience.

Here are a couple of options.

  • Make the requests through a local proxy (just pass through).
  • Use a proxy + Rails so that you can work the way Ember.js wants you to.
  • Use CORS requests to get around the XSS issue.

It seems like the canonical approach to Ember.js is to use a local Rails app to serve up json to an Ember.js app. From what research my team has done, it doesn't seem like CORS is a commmon way to work with Ember.js.

EDIT:

Regarding the comment below, this is really more a question of how to use Ember-data with an external api rather than Ember.js itself.

bobbywilson0
  • 1,032
  • 6
  • 17
  • have you had some Ember specific problem when trying CORS as client-server communication? – Misha Reyzlin Oct 04 '12 at 15:34
  • Mostly this was an issue of Ember-data not really having support for it. I would be open to other data abstractions, but from what I have found Ember-data is the only one that is still being actively worked on. – bobbywilson0 Oct 04 '12 at 15:54

2 Answers2

2

Server-client communication is not something that Ember.JS is solving for you, it uses jQuery for this, so there shouldn't be any kind of restriction on Ember.JS' side.

All the things you listed are legitimate ways of dealing with APIs that are served from different domains, depending on the user agent support you want to achieve (some clients don't support CORS at all, or in limited forms).

Misha Reyzlin
  • 12,998
  • 4
  • 51
  • 62
  • Thanks for the response. You're right server-client communication isn't really an Ember thing as much, but I do think it is a problem that Ember-data is trying to solve with it's data model abstraction. For example, the data store REST adapter is handling server-client communication to access json endpoints it will turn into models. – bobbywilson0 Oct 04 '12 at 15:43
  • 1
    Looking through README on ember-data, it seems like you can override builtin "find" method of your adapter. In their examples they are still using jQuery, and jQuery should be good with CORS. If you would provide a simplified version of your code that doesn't work – it could be much easier to tell what's wrong. You can use SoundCloud API for testing as it's CORS enabled ;-) – Misha Reyzlin Oct 04 '12 at 16:06
0
              **Approach 1**

If you look at this blog post: http://eng.netwallet.com/2012/04/17/simple-cross-domain-ajax-with-a-wormhole-5/

On the host page, they are using porthole.js and an Ember object that sets up the porthole windowProxy and listens for messages from it.

Porthole.js is a small Javascript library that makes it safe and easy to communicate with cross domain iFrames.

You can always use this approach from within ember-data and the RestAdapter to override things like gryzzly mentioned.

           **Approach 2**

Also in the post below, they are doing cors using goliath as proxy to work with ember-data and elasticsearch but with their own custom adapter:

http://www.elasticsearch.org/tutorials/2012/08/22/javascript-web-applications-and-elasticsearch.html

The whole code from the post is here: https://gist.github.com/3369662

brg
  • 3,615
  • 6
  • 33
  • 62