Tudor Vintilescu
Tudor Vintilescu

Reputation: 1460

Ember-cli server - proxying not working

I'm new to Ember CLI and have been trying to get the ember cli server to proxy requests to my Rails backend with no success.

I have Ember CLI v.0.39 installed, and have put up a route to fetch a model from the server by AJAX:

return Em.$.getJSON('/users').then(function(result){
      return Em.A(result);
)};

I run ember s --proxy "http://127.0.0.1:3000" this being my Rails endpoint.

The request is being made from the browser, but I find no trace of it being forwarded to the Rails endpoint. The javascript console mentions a bug about an 'Route: undefined' error,

I have also found info on the web that v.0.39 had some problems in this regard and have fetched and npm link-ed the latest version from the git ember-cli rep.

  Error while loading route: undefined 

I do think that the error message is strictly a result of the AJAX response being void.

Any ideas would be greatly appreciated.

Upvotes: 2

Views: 1571

Answers (1)

HeroicEric
HeroicEric

Reputation: 876

Using master, this works fine for me. There are a couple syntax issues with your example though. Your route should look something like this:

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return Ember.$.getJSON('/users').then(function(result){
      return Ember.A(result);
    });
  }
});

A couple things that might help:

  • Make sure that you have your rails server running on port 3000 when you start up the ember server.
  • Check the logs for the rails server to verify that it's working. The network tab in the chrome dev tools will still show it as http://localhost:4200
  • Make sure that you both ran npm link in your clone of ember-cli and also ran npm link ember-cli from you ember-cli app directory.

Upvotes: 3

Related Questions