-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 http dev_server setting properly in the proxy #1420
Conversation
I verified that
(Note, this same behavior exists in 3.0, 3.4, and 4.0-pre versions of webpacker) |
Thanks, @chrisjohnson I will take a look at this later today. |
@chrisjohnson I have merged #1425 Does that solve this issue for you? The reason to keep it strict was this The HMR requests to dev server will fail unless both uses same scheme. |
@gauravtiwari : I see, our setups differ -- my webpack-dev-server is also terminated by the https proxy, which is why I don't get those The other PR does not fix the issue for me though. If you see this link: http://www.rubydoc.info/gems/rack/Rack/Request/Helpers#scheme-instance_method You can see how As far as I can tell, both my PR and #1425 are compatible with one another, and seem like they will, once combined, solve the issue for all proxy configurations. I don't believe the error you are getting in your console is related to the code we are changing here. I've rebased mine on top of latest master and tested both with and without my change. Without my change, the issue is not solved, and with my change, the issue is solved. Look forward to your feedback! |
If dev_server is not set for https, the proxy should always forward requests to http, irrespective of the source request's scheme The logic for which headers to change comes from looking at the Rack::Proxy source, which determines if it should make an ssh request by using http://www.rubydoc.info/gems/rack/Rack/Request/Helpers#scheme-instance_method
Thanks, @chrisjohnson PR merged but the above still is going to be an issue if your app uses HMR or webpacker in inline mode, although totally unrelated to this fix so no worries :) Anyway, if using HMR then dev server must use HTTPS mode if it's an HTTPS request since the requests above are directly made to dev server from browser client instead of going through a proxy. |
We use HMR with HTTPS requests by also proxying the Thanks so much for merging this! |
Of course, if dev server requests are proxied too then everything should work just fine 👍 Your welcome and thanks for sharing. |
@gauravtiwari Any chance you could make a git tag including this change so I can update our Gemfile to consume it? |
If dev_server is not set for https, the proxy should always forward requests to http, irrespective of the source request's scheme
The logic for which headers to change comes from looking at the Rack::Proxy source,
which determines if it should make an ssl request by using
http://www.rubydoc.info/gems/rack/Rack/Request/Helpers#scheme-instance_method
Background
In our dev environment, we use an nginx proxy which terminates SSL and talks to the rails app over http. Our webpacker.yml contains the following config:
Which does effectively start
webpack-dev-server
in http mode, but the rails proxy baked into webpacker does not take this setting into account when forwarding requests ontowebpack-dev-server
. Instead, it blindly passes in env without mutating it, whichRack::Proxy
then uses to determine that it should communicate towebpack-dev-server
over https, matching the source request.If there's some circumstance I'm ignoring/missing here, please let me know, I welcome feedback.