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

Add 'lan' option (modify the option name to ‘useLocalIp’ for more semantic) #901

Merged
merged 11 commits into from
Jun 18, 2017

Conversation

sliwey-zz
Copy link
Contributor

@sliwey-zz sliwey-zz commented May 3, 2017

Let the browser open with local IP.

What kind of change does this PR introduce?
feature

Did you add or update the examples/?
no

Summary
According to #147, server can be accessed via IP, but when set host to 0.0.0.0 and open to true, the browser will open http://0.0.0.0, but it's inaccessible.

This PR allows to set lan useLocalIp to true, so that the browser can open with local IP.

Example usage in webpack config:

devServer: {
  host: '0.0.0.0',
  disableHostCheck: true,
  open: true,
  // lan: true,  // set true to let the browser open with local IP
  useLocalIp: true,  // set true to let the browser open with local IP
  ...
}

Does this PR introduce a breaking change?
no

  Let the browser open with local IP.
@jsf-clabot
Copy link

jsf-clabot commented May 3, 2017

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented May 3, 2017

Codecov Report

Merging #901 into master will decrease coverage by 0.09%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #901     +/-   ##
=========================================
- Coverage   72.23%   72.13%   -0.1%     
=========================================
  Files           4        4             
  Lines         461      463      +2     
  Branches      138      139      +1     
=========================================
+ Hits          333      334      +1     
- Misses        128      129      +1
Impacted Files Coverage Δ
lib/util/createDomain.js 42.85% <50%> (+2.85%) ⬆️

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 8d5f252...345201e. Read the comment docs.

@@ -1,13 +1,31 @@
"use strict";
const url = require("url");
const networkInterfaces = require("os").networkInterfaces();

function getLocalIP() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you write tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I will add some tests later.

@@ -0,0 +1,19 @@
"use strict";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use https://www.npmjs.com/package/internal-ip (first choice) or https://www.npmjs.com/package/dev-ip to replace the need for this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I will use internal-ip to replace this file.


module.exports = function createDomain(options) {
const protocol = options.https ? "https" : "http";

// the formatted domain (url without path) of the webpack server
return options.public ? `${protocol}://${options.public}` : url.format({
protocol: protocol,
hostname: options.host,
hostname: options.lan ? getLocalIP() : options.host,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel that lan is semantic for this feature. options.useLocalIp or some such would probably be easier to understand at first glance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, agreed. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shellscape You're right, I will change the word to useLocalIp to make it more semantic.
And thank you for giving me all the advice.

@sliwey-zz sliwey-zz changed the title Add 'lan' option Add 'lan' option (modify the option name to ‘useLocalIp’ for more semantic) Jun 15, 2017
@shellscape
Copy link
Contributor

Looks good. Please sign the CLA (#901 (comment)) and we can get this merged

@sliwey-zz
Copy link
Contributor Author

@shellscape I have already signed the CLA.

@shellscape shellscape merged commit 7b3a42a into webpack:master Jun 18, 2017
This pull request was closed.
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.

5 participants