Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through entire path when proxying #1874

Merged
merged 2 commits into from
Sep 5, 2014

Conversation

tstirrat
Copy link
Contributor

@tstirrat tstirrat commented Sep 5, 2014

When using the http-proxy blueprint, a proxied request does not pass through the full path. e.g.

ember g http-proxy api http://localhost:5000
ember serve

http://localhost:4200/api/foo - [proxied] -> http://localhost:5000/foo # unexpected

http://localhost:4200/api/foo - [proxied] -> http://localhost:5000/api/foo # expected

It looks like it is not going to be supported in node-http-proxy since they removed "proxy table" support: http-party/node-http-proxy#386

The fix is simple.

When using the proxy blueprint a request to `/api/posts`
would send the request as `/posts` to the proxied server.
This updates the proxy blueprint to prepend the proxy base on
proxied requests.
@tstirrat
Copy link
Contributor Author

tstirrat commented Sep 5, 2014

This PR doesn't cover it, but do you see value in handling complex cases when a path is specified in the destination?

e.g.

ember g http-proxy api http://localhost:5000/api/v1

http://localhost:4200/api/foo - [proxied] -> http://localhost:5000/api/v1/foo
ember g http-proxy foo http://localhost:5000/bar

http://localhost:4200/foo/123 - [proxied] -> http://localhost:5000/bar/123

@rwjblue
Copy link
Member

rwjblue commented Sep 5, 2014

If someone needs that level of customization, we should simply encourage they edit the generated file to add it.

rwjblue added a commit that referenced this pull request Sep 5, 2014
Pass through entire path when proxying
@rwjblue rwjblue merged commit 6569297 into ember-cli:master Sep 5, 2014
@tstirrat tstirrat deleted the proxy-path-passthru branch September 5, 2014 03:11
@trek
Copy link
Contributor

trek commented Sep 8, 2014

I'd like some more discussion around this.

Originally I didn't pass the url the api is mounted at on purpose to support the case where (in production) you need to proxy from one UI to many difference services and so need your development proxying behavior to match your deployment proxying behavior.

For example, if you have a UI that uses data from http://myapp.info and 'http://yourapp.ninja/api`, you'd have a production setup in something like nginx:

location /myapp  {
    proxy_pass http://myapp.info;
}

location /ninjas  {
    proxy_pass http://yourapp.ninja/api;
}

and so would generate two proxies in development mode

ember g http-proxy myapp
ember g http-proxy ninjas

In this case you want ajax('/ninjas/battles/12') to eventually request to http://yourapp.ninja/api/battles/12 not http://yourapp.ninja/api/ninjas/battles/12.

If you're developing one UI against one service and will be deploying them both under the same domain (so want the behavior of this PR), you'd just generate an http-proxy without a namespace:

ember g http-proxy

which should mount at / after asset loading attempts, yeah?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants