samedi 29 août 2015

ember-cli with rails-api app working in localhost but not in heroku

I'm using the rails-api gem to generate api for my app and using Ember-cli, pretty much the same setup as here :

http://ift.tt/18xl3mf

I did, however, namespace my api by using scope in routes.rb like so:

scope '/api' do 
    root 'teachers#index'
    resources :teachers, except: [:new, :edit]
    ...   

  end

Now, when I do

ember server --proxy http://localhost:3000/api/

my app works on localhost.

I then deployed both applications to heroku: the rails to, say, backend.herokuapp.com and the ember-app to frontend.herokuapp.com

I used this buildpack:

http://ift.tt/1pWW3b7

and as per the instructions there, used

heroku config:set API_URL=http://ift.tt/1LJdeLJ

and

heroku config:set API_PREFIX_PATH=/api/

Yet when I go to frontend.herokuapp.com, my data never loads. It shows up as json on backend.herokuapp.com clearly, but when I try and load my frontend.herokuapp.com, I get this error:

SyntaxError: Unexpected token <
    at Object.parse (native)
    at ie.parseJSON (http://ift.tt/1Jp8QLT)
    at q (http://ift.tt/1LJdkmh)
    at r (http://ift.tt/1Jp8QLV)
    at XMLHttpRequest.t (http://ift.tt/1LJdhXE)

This error never shows on the development side.

Then, when I try to create a new Teacher using the ember interface, I get this error:

POST http://ift.tt/1Jp8QLX 405 (Not Allowed)

What is causing these errors? How do I get my ember app to communicate with my rails-api app on Heroku?




Aucun commentaire:

Enregistrer un commentaire