javascriptember.jsember-model

Same origin policy when developing on local machine


Im using Ember and Ember-Model to develop a front end which is calling a Spring/Rest/MongoDB back end, which is all running on my local machine for development purposes, but I get the same origin policy error for my call.

I want to know what the common work around for this is.

Here is my code:

App = Ember.Application.create();

App.Router.map(function(){

});

App.IndexRoute = Ember.Route.extend({
   model: function(){
       return App.User.find();
   }
});

App.User = Ember.Model.extend({
    lastName: Ember.attr()
});

App.User.adapter = Ember.Adapter.create({
    findAll: function(klass, records) {
        $.getJSONP("http://localhost:8080/users").then(function(data) {
            records.load(klass, data.users);
        });
    }
})

Solution

  • The same origin policy on localhost is the same as on the rest of the web. However, if you open your web app as a file (ie. the address starts with file:/// every other uri, even those of other files, will have a different origin.

    To solve this, serve your app from a server running on your own machine, than look at it by going to http://localhost.