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: improve host output and fix open #2892

Merged
merged 7 commits into from
Dec 2, 2020
Merged

feat: improve host output and fix open #2892

merged 7 commits into from
Dec 2, 2020

Conversation

alexander-akait
Copy link
Member

  • 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

fixes #2874

Breaking Changes

No

Additional Info

inspired by CRA

@alexander-akait
Copy link
Member Author

/cc @hiroppy

@alexander-akait
Copy link
Member Author

When you use 0.0.0.0 or ::, our output is:

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Local: http://localhost:8081/
<i> [webpack-dev-server] On Your Network: http://192.168.0.5:8081/

When it is not IP:

<i> [webpack-dev-server] Project is running at http://local-dev.io:8081/

lib/Server.js Outdated
if (hostname === '0.0.0.0' || hostname === '::') {
prettyHostname = 'localhost';

const localIP = internalIp.v4.sync();
Copy link
Contributor

@ylemkimon ylemkimon Dec 1, 2020

Choose a reason for hiding this comment

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

Suggested change
const localIP = internalIp.v4.sync();
const localIP = hostname === '::' ? internalIp.v6.sync() : internalIp.v4.sync();

Copy link
Member Author

Choose a reason for hiding this comment

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

It is for terminal output, developer should copy past it from terminal, IPv6 is not supported in many browsers

Copy link
Contributor

Choose a reason for hiding this comment

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

url automatically formats IPv6 hostname with brackets, which most browsers support including IE 11, e.g., http://[::]:8080. I think IPv6 should take precendence over IPv4, if available.

Copy link
Member Author

Choose a reason for hiding this comment

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

make sense, I hope this does not scare developers

lib/Server.js Outdated
Comment on lines 599 to 602
if (
/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(localIP)
) {
// Address is private, format it for later use
Copy link
Contributor

@ylemkimon ylemkimon Dec 1, 2020

Choose a reason for hiding this comment

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

I think this check is not needed, as 0.0.0.0 (::) will bind to a public address, if available.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can have local public IP (it is very rare edge case, but it is possible), for example I can run it on my server with public IP

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I think the public IP should be printed.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case we print two IP - local and network

Copy link
Contributor

@ylemkimon ylemkimon Dec 1, 2020

Choose a reason for hiding this comment

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

IMHO, I see no reason not to print the internal IP (the IP address of the NIC) if it's a public one. It's still a network IP, just not a LAN.

Copy link
Member Author

@alexander-akait alexander-akait Dec 1, 2020

Choose a reason for hiding this comment

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

I don't have strong opinion here, it was inspired by CRA and their feedback, but maybe you are right

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's simplify it, we will change it in future after feedback

@@ -28,7 +28,7 @@ exports[`CLI --hot webpack 4 1`] = `
`;

exports[`CLI --hot webpack 5 1`] = `
Copy link
Contributor

@ylemkimon ylemkimon Dec 1, 2020

Choose a reason for hiding this comment

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

Note snapshots should be updated twice, each for webpack 4 and 5.

@@ -8,27 +8,27 @@ function createDomain(options, server) {
// use location hostname and port by default in createSocketUrl
Copy link
Contributor

@ylemkimon ylemkimon Dec 1, 2020

Choose a reason for hiding this comment

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

WIth showStatus() now using its own logic, this is only used in client entries. I think this can be refactored in the future PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think logic for terminal output and for entries is different, it is similar in some places, but it is for different purpose

@codecov
Copy link

codecov bot commented Dec 1, 2020

Codecov Report

Merging #2892 (2846faa) into master (143ce32) will increase coverage by 0.07%.
The diff coverage is 89.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2892      +/-   ##
==========================================
+ Coverage   92.45%   92.52%   +0.07%     
==========================================
  Files          38       37       -1     
  Lines        1246     1258      +12     
  Branches      324      333       +9     
==========================================
+ Hits         1152     1164      +12     
  Misses         89       89              
  Partials        5        5              
Impacted Files Coverage Δ
lib/Server.js 94.86% <88.88%> (-0.60%) ⬇️
lib/utils/createDomain.js 100.00% <100.00%> (ø)
lib/servers/SockJSServer.js 94.11% <0.00%> (ø)
lib/servers/WebsocketServer.js 94.11% <0.00%> (ø)
client-src/clients/WebsocketClient.js 58.13% <0.00%> (ø)
client-src/clients/SockJSClient.js 65.90% <0.00%> (+4.54%) ⬆️

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 143ce32...2846faa. Read the comment docs.

@alexander-akait
Copy link
Member Author

/cc @ylemkimon Done

@alexander-akait
Copy link
Member Author

IPv6 is not supported by github actions, we can't test it 😞

@alexander-akait
Copy link
Member Author

@ylemkimon ylemkimon mentioned this pull request Dec 2, 2020
6 tasks
@alexander-akait alexander-akait merged commit 9e65c24 into master Dec 2, 2020
@alexander-akait alexander-akait deleted the issue-2874 branch December 2, 2020 13:41
this.options.dev &&
typeof this.options.dev.publicPath !== 'undefined'
) {
this.options.info(

Choose a reason for hiding this comment

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

@alexander-akait looks like this.options.info should be replaced with this.logger.info

Copy link
Member Author

Choose a reason for hiding this comment

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

Already fixed in master

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.

v4.0.0-beta.0 and host option
3 participants