getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Unable to set the API's url in Ep.RestAdapter #115

Closed Manumie closed 10 years ago

Manumie commented 10 years ago

I'm testing EPF in a dummy application that I got working with Ember Data.

I'm using Ember App Kit.

I have a simple route:

app/routes/quotes.js
export default Em.Route.extend({
  return this.session.query('quote');
});

The app hits a basic REST API (node + express) on http://locahost:4444

When my app enters the /quotes/ route, I get this error:

Assertion failed: Error while loading route: {readyState: 4, getResponseHeader: function() { ... }, getAllResponseHeaders: function() { ... }, setRequestHeader: function() { ... }, overrideMimeType: function() { ... }, statusCode: function() { ... }, abort: function() { ... }, state: function() { ... }, always: function() { ... }, then: null, promise: function() { ... }, pipe: function() { ... }, done: function() { ... }, fail: function() { ... }, progress: function() { ... }, complete: function() { ... }, success: function() { ... }, error: function() { ... }, responseText: <!DOCTYPE html>
<html>
(...snip content of my app's index.html...)
</html>

The Ajax request from EPF RestAdapter is sent on http://localhost:8080/model)s that is the app's url with the weird route model)s

I have tried setting the url as advised here:

app/adapters/application.js
export default Ep.RestAdapter.extend({
  url: 'http://localhost:4444'
});

I've also tried:

app/adapters/application.js
export default Ep.RestAdapter.reopen({
  url: 'http://localhost:4444'
});

None worked.

What am I missing ?

Manumie commented 10 years ago

Updates: I set a breakpoint on RestAdapter.BuildURL and checked:

> this.url
""
> url
[""]

So my setting in app/adapters/application.js is ignored.

As a matter of fact, I tried setting a breakpoint on the line

  url: 'http://localhost:4444'

but the debugger doesn't pause.

I don't get it...

ghempton commented 10 years ago

There is an issue with the way ember app kit resolves types in conjunction with how epf guesses the names of types. Try explicitly adding a typekey property to the model class:

Post.reopenClass({
  typeKey: 'post'
})
ghempton commented 10 years ago

There is an issue with the way ember app kit resolves types in conjunction with how epf guesses the names of types. Try explicitly adding a typekey property to the model class:

Post.reopenClass({
  typeKey: 'post'
})
ghempton commented 10 years ago

There is an issue with the way ember app kit resolves types in conjunction with how epf guesses the names of types. Try explicitly adding a typekey property to the model class:

Post.reopenClass({
  typeKey: 'post'
})
Manumie commented 10 years ago

Thanks for your tip : I thought the model)s thing might be produced by the resolver.

Adding typeKey: 'post' in my model, the route is now localhost:8000/quotes

Still, EPF keeps hitting the API on localhost:8000 whereas it should be localhost:4444

How should I set the url property of the adapter ?

ghempton commented 10 years ago

Sorry for the delayed response. I believe that if you define the adapter in app/adapters/main.js (instead of application.js) it will fix it.