tonycoco / heroku-buildpack-ember-cli

A Heroku Buildpack for Ember CLI Applications
MIT License
321 stars 121 forks source link

Proxy between two Heroku apps not receiving API_PREFIX_PATH #66

Closed johnmosesman closed 9 years ago

johnmosesman commented 9 years ago

Hi,

I have two Heroku apps (Ember CLI & Rails), and it appears from the logs that the Ember app is sending the correct request /api/categories, but the Rails Heroku app is receiving the request without the /api/ prefix.

Here are the Ember logs (you can see the GET /api/categories on the second to last line):

2015-03-01T00:17:56.249010+00:00 heroku[router]: at=info method=GET path="/categories" host=time-keeper-ember.herokuapp.com request_id=e48b97ac-30c2-4465-bf78-71f0e09fa9ed fwd="68.12.20.61" dyno=web.1 connect=1ms service=1ms status=304 bytes=233
2015-03-01T00:17:56.248347+00:00 app[web.1]: measure#nginx.service=0.001 request_id=e48b97ac-30c2-4465-bf78-71f0e09fa9ed
2015-03-01T00:17:56.457100+00:00 heroku[router]: at=info method=GET path="/assets/vendor-a2fd2ed071d75f655927dd1c0e15f636.css" host=time-keeper-ember.herokuapp.com request_id=c71965d8-6931-45a6-ae70-b11a6962e65a fwd="68.12.20.61" dyno=web.1 connect=1ms service=1ms status=304 bytes=266
2015-03-01T00:17:56.457215+00:00 heroku[router]: at=info method=GET path="/assets/time-keeper-ember-bc928484a6acac5c793437ce6c8ad8c5.css" host=time-keeper-ember.herokuapp.com request_id=b9bb55b3-4838-421c-8da8-06c341f61f73 fwd="68.12.20.61" dyno=web.1 connect=1ms service=1ms status=304 bytes=267
2015-03-01T00:17:56.454337+00:00 heroku[router]: at=info method=GET path="/assets/vendor-908b07c7849a3d82e758ab826952ca9c.js" host=time-keeper-ember.herokuapp.com request_id=3b98233e-faaa-4d10-8345-4547172a8bfa fwd="68.12.20.61" dyno=web.1 connect=1ms service=1ms status=304 bytes=267
2015-03-01T00:17:56.718343+00:00 heroku[router]: at=info method=GET path="/assets/time-keeper-ember-98e1be7ebadd983d8a7e976fb246f744.js" host=time-keeper-ember.herokuapp.com request_id=723e3d69-6c45-408b-8cba-ab0a049d1f4f fwd="68.12.20.61" dyno=web.1 connect=1ms service=1ms status=304 bytes=266
2015-03-01T00:17:57.258396+00:00 heroku[router]: at=info method=GET path="/api/categories" host=time-keeper-ember.herokuapp.com request_id=1f54841c-48d6-4516-8dda-c2661c7e419c fwd="68.12.20.61" dyno=web.1 connect=1ms service=36ms status=404 bytes=290
2015-03-01T00:17:57.258964+00:00 app[web.1]: measure#nginx.service=0.036 request_id=1f54841c-48d6-4516-8dda-c2661c7e419c

And the Rails logs:

2015-03-01T00:17:57.253106+00:00 heroku[router]: at=info method=GET path="/categories" host=time-keeper.herokuapp.com request_id=1f54841c-48d6-4516-8dda-c2661c7e419c fwd="68.12.20.61, 10.123.86.56,54.161.37.34" dyno=web.1 connect=0ms service=16ms status=404 bytes=306
2015-03-01T00:17:57.238123+00:00 app[web.1]: Started GET "/categories" for 54.161.37.34 at 2015-03-01 00:17:57 +0000
2015-03-01T00:17:57.248397+00:00 app[web.1]:
2015-03-01T00:17:57.248402+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/categories"):
2015-03-01T00:17:57.248404+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2015-03-01T00:17:57.248405+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2015-03-01T00:17:57.248407+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:38:in `call_app'
2015-03-01T00:17:57.248409+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `block in call'
2015-03-01T00:17:57.248411+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2015-03-01T00:17:57.248412+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
2015-03-01T00:17:57.248414+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `tagged'
2015-03-01T00:17:57.248415+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `call'
2015-03-01T00:17:57.248417+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2015-03-01T00:17:57.248418+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2015-03-01T00:17:57.248420+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
2015-03-01T00:17:57.248421+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
2015-03-01T00:17:57.248423+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
2015-03-01T00:17:57.248424+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
2015-03-01T00:17:57.248426+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2015-03-01T00:17:57.248427+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2015-03-01T00:17:57.248429+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2015-03-01T00:17:57.248430+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2015-03-01T00:17:57.248432+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2015-03-01T00:17:57.248433+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2015-03-01T00:17:57.248434+00:00 app[web.1]:
2015-03-01T00:17:57.248435+00:00 app[web.1]:

This is my config for the Ember app:

=== time-keeper-ember Config Vars
API_PREFIX_PATH: /api/
API_URL:         https://time-keeper.herokuapp.com/
BUILDPACK_URL:   https://github.com/tonycoco/heroku-buildpack-ember-cli.git

Ember - time-keeper-ember.herokuapp.com Rails - time-keeper.herokuapp.com

When I run my Ember app locally and proxy to the production Rails app (ember serve --proxy https://time-keeper.herokuapp.com), it works fine, so I believe the problem is between the two Heroku apps themselves.

I saw this closed issue, but it appears to be a different problem from the one I'm having.

Any ideas if this could be from the buildpack? If I didn't supply enough or the right kind of information let me know. Thank you so much for this buildpack—it is amazing. This is my final hurdle. :/

tonycoco commented 9 years ago

This is by design. But, we should have a flag to push that path through to your API as well. Basically the proxy-pass chops off the API_PREFIX_PATH when it goes to the actual API. But, yeah, we should fix this so it works.

johnmosesman commented 9 years ago

Hey Tony,

I'm not sure what you mean. If the proxy removes the prefix path, where does the prefix path get used?

tonycoco commented 9 years ago

The API_PREFIX_PATH is probably a bad name... looking at refactoring that.

Basically, it is the path that is proxy_pass'ed to the API_URL, so, requests from the Ember app to http://<YOUR_HEROKU_EMBER_CLI_APP_HOSTNAME>/api/v1/ping become http://<API_URL>/v1/ping...

Now, you could set API_URL to anything you want, if you wish to keep the /api prefix, for instance, setting API_URL to http://example.com/api/ would have requests to http://<YOUR_HEROKU_EMBER_CLI_APP_HOSTNAME>/api/v1/ping become http://example.com/api/v1/ping. Hope that helps.

tonycoco commented 9 years ago

Reference: #62