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

Handle "self" link protocol when proxied #45

Closed
MichaelBoselowitz opened this issue Aug 4, 2015 · 5 comments
Closed

Handle "self" link protocol when proxied #45

MichaelBoselowitz opened this issue Aug 4, 2015 · 5 comments

Comments

@MichaelBoselowitz
Copy link

I currently have json-api setup behind a Nginx proxy. The proxy sets up a SSL tunnel. All the clients speak only over HTTPS, but everything behind the proxy is only HTTP.

Self links derive their protocol from the incoming request protocol only. The simple fix is to use the traditional X-Forwarded-Proto header instead (if set).

There is probably a better way to handle this, but I'd like to get your thoughts before I post a PR. I just change this line to this:

it.uri = (req.get('X-Forwarded-Proto') || req.protocol) + "://" + req.get("Host") + req.originalUrl;
@MichaelBoselowitz MichaelBoselowitz changed the title Handle "self" link proxied protocol Handle "self" link protocol when proxied Aug 4, 2015
@ethanresnick
Copy link
Owner

Good catch!

I've also used this library behind a proxy, and I think I solved this problem by setting express' trust proxy setting to true. IIRC, that then updates req.protocol to uses the value from X-Forwarded-Proto.

Is there some reason not to solve this with trust proxy? (e.g. some security concern I don't know about?) If so, we can talk about other solutions. Otherwise, I'd just use that switch :)

@MichaelBoselowitz
Copy link
Author

I didn't know that option existed! This is exactly what I wanted!

That option certainly feels like the proper way to handle this case. I cannot think of any issues with using it (the API is completely isolated behind the proxy). As you may be able to discern, I've never used Node/Express behind a proxy before.

Thanks for the super quick responses to my issues! This is an extremely helpful library, I really appreciate your work. Let me know if I can contribute in any way besides spamming up the issues section. :)

@ethanresnick
Copy link
Owner

I'm glad that worked, and that the library's been useful to yiu! Also, thanks so much for your offer to contribute; your help would certainly be appreciated! Are there any open issues you might want to take a stab at?

@MichaelBoselowitz
Copy link
Author

#17 looks like it would be very helpful to me in the near future. When I start the next phase of my project, I'll do some exploring into that issue and see what I can come up with.

@ethanresnick
Copy link
Owner

Awesome! Thanks Michael!

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

No branches or pull requests

2 participants