K
K
Klaus Kater2016-03-24 10:56:25
Ember.js
Klaus Kater, 2016-03-24 10:56:25

How to make Emberjs friends with a third-party api, on a different host?

Good day. Picking ember js, version 2.4. And there adapters have such a parameter as a host, which indicates where to get data for models, etc.

export default DS.RESTAdapter.extend({
  host: 'http://localhost:8000/api'
});

The only problem is that Ajax requests go to the host, which do not like cross-domain very much, and of course they say No 'Access-Control-Allow-Origin' header is present on the requested resource.
The question is, what is the meaning of the parameter? even if on the same host but on a different port, it cannot take the data.
In this regard, there are many problems with ember, firstly, from a certain version, all information in the documents has disappeared, how to run ember not with its built-in server. Does the ember need Nod, or can it be untied and run using more standard methods. What to do with templating engines, etc.. but this is a topic for another question.
In this situation, there is another way out, try to make a proxy to your api from the Ember Node. Those. forward all requests to a neighboring server with a different port. But due to the small knowledge of the node, I can’t get to the bottom of its configs in the ember version.
I don’t want to do a backend on a node, I’m a python adherent, and php people generally hate this very node)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Romanov, 2016-03-24
@kurojneko

what is the meaning of the parameter?

Have you set up cross-domain on the backend?
standard as well as any library or framework. If the templates are not precompiled, then you can use the following snippet:
(function(){
  Ember.Application.initializer({
    name: 'load-templates',
    initialize: function(container, application) {
      application.deferReadiness();

      var templates = ['index', 'users'];

      Ember.RSVP.all(templates.map(function(item){
        return Ember.$.get("PATH_TO_DIRECTORY_WITH/" + item + ".hbs")
      })).then(function(all){
        all.forEach(function(hbs, i){
          Ember.TEMPLATES[templates[i]] = Ember.Handlebars.compile(hbs);
        });
      }).finally(function(){
        application.advanceReadiness();
      });
    }
  });
  
  var App = Ember.Application.create();
})();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question