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

feat(client): allow sock host to use browser location's host #2859

Closed
wants to merge 1 commit into from
Closed

feat(client): allow sock host to use browser location's host #2859

wants to merge 1 commit into from

Conversation

gluxon
Copy link

@gluxon gluxon commented Nov 25, 2020

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Yes!

Motivation / Use-Case

This is templated off of commit 0835a19/#2341, but for the browser location's hostname instead of its port.

This is useful when webpack-dev-server is being accessed behind a reverse proxy with a hostname that's not known at build time.

Breaking Changes

No breaking changes.

Additional Info

None

This is templated off of commit 0835a19/#2341, but for the browser
location's hostname instead of its port.

Useful when webpack-dev-server is being accessed behind a reverse proxy.
@gluxon
Copy link
Author

gluxon commented Nov 25, 2020

I'll sign the CLA soon. Just sent it to my company's legal team to review.

@codecov
Copy link

codecov bot commented Nov 25, 2020

Codecov Report

Merging #2859 (136cf54) into master (4ab1f21) will decrease coverage by 0.21%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2859      +/-   ##
==========================================
- Coverage   93.77%   93.55%   -0.22%     
==========================================
  Files          34       34              
  Lines        1333     1335       +2     
  Branches      381      382       +1     
==========================================
- Hits         1250     1249       -1     
- Misses         81       84       +3     
  Partials        2        2              
Impacted Files Coverage Δ
client-src/default/utils/createSocketUrl.js 100.00% <100.00%> (ø)
lib/utils/updateCompiler.js 97.14% <0.00%> (-2.86%) ⬇️
lib/Server.js 96.36% <0.00%> (-0.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ab1f21...136cf54. Read the comment docs.

@gluxon
Copy link
Author

gluxon commented Nov 25, 2020

It just occurred to me that location is a valid hostname. 😕 I wonder if passing in a boolean param useLocationHostname would be acceptable.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is use case?

@jsg2021
Copy link

jsg2021 commented Nov 26, 2020

I believe you can set the host to 0.0.0.0 to get this right now.

@gluxon
Copy link
Author

gluxon commented Nov 26, 2020

Thanks to you both for taking a look so quickly!

@jsg2021 I did notice the conditional that sets hostname to loc.host if it's 0.0.0.0, but is there a way get this behavior without having webpack listening on all network interfaces?

@alexander-akait I'm trying to support local and remote development for my team a bit better. The app/framework I'm using allows developers to create publicly accessible URLs that expose services running within a container. (Ex: something.dev.acme.local)

The problem is that wds always tries to connect to localhost:8080/sockjs-node instead of the dynamically created URL, which fails since wds is being proxied.

Setting public is another option, but that requires people to tweaking configs and restarting. Ideally sockjs on the frontend just connects to the root-relative path /sockjs-node and no one has to tweak configs.

@alexander-akait
Copy link
Member

alexander-akait commented Nov 26, 2020

Can you switch on v4 branch? Only security fixes for v3 (if it is possible)

@gluxon
Copy link
Author

gluxon commented Nov 26, 2020

Certainly. Although I'm not confident in this implementation anymore since we'd cause unexpected behavior for users that actually want to set their host to location (literally). Regardless of how rare that may be, it's a bit of a code smell.

I'll think about this for a bit and open a different PR against the v4 branch. Thanks again for taking a look!

@gluxon gluxon closed this Nov 26, 2020
@jsg2021
Copy link

jsg2021 commented Nov 27, 2020

@gluxon I meant on the client include entry point:

webpack-dev-server/client?http://0.0.0.0:${devPort}

this won't effect the server binding

@gluxon
Copy link
Author

gluxon commented Nov 27, 2020

@jsg2021 Ah I misunderstood. That's a good workaround for 3.11.0, thanks!

I noticed that using window.location is the new default from looking at #2869. Glad that change merged. Thanks @ylemkimon

@gluxon gluxon deleted the dynamic-sock-host branch November 27, 2020 22:24
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.

None yet

3 participants