From 08c8caac456eb5500587c0b97d426a948d3d2515 Mon Sep 17 00:00:00 2001 From: NewFuture Date: Fri, 28 Oct 2016 09:10:59 +0800 Subject: [PATCH 1/2] fixed ipv6 parsing and listening [::] with latest --- bin/webpack-dev-server.js | 16 +++++++++------- client/index.js | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index 3039372515..3fc9214a0f 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -281,8 +281,15 @@ function processOptions(wpOpt) { var protocol = options.https ? "https" : "http"; + // the formated domain (url without path) of the webpack server + var domain = url.format({ + protocol: protocol, + hostname: options.host, + port: options.socket ? 0 : options.port.toString() + }); + if(options.inline !== false) { - var devClient = [require.resolve("../client/") + "?" + protocol + "://" + (options.public || (options.host + ":" + options.port))]; + var devClient = [require.resolve("../client/") + "?" + (options.public ? protocol + "://" + options.public : domain)]; if(options.hotOnly) devClient.push("webpack/hot/only-dev-server"); @@ -308,12 +315,7 @@ function processOptions(wpOpt) { })); } - var uri = url.format({ - protocol: protocol, - hostname: options.host, - pathname: options.inline !== false ? "/" : "webpack-dev-server/", - port: options.socket ? 0 : options.port.toString() - }); + var uri = domain + (options.inline !== false ? "/" : "webpack-dev-server/"); var server = new Server(compiler, options); diff --git a/client/index.js b/client/index.js index bdcff0e78e..719d3b7260 100644 --- a/client/index.js +++ b/client/index.js @@ -89,7 +89,9 @@ var onSocketMsg = { var hostname = urlParts.hostname; var protocol = urlParts.protocol; -if(urlParts.hostname === "0.0.0.0") { + +//check ipv4 and ipv6 `all hostname` +if(hostname === "0.0.0.0" || hostname === "::") { // why do we need this check? // hostname n/a for file protocol (example, when using electron, ionic) // see: https://github.com/webpack/webpack-dev-server/pull/384 From 491f96e8ea3cc7973b285d9a2905855cd2d6f52c Mon Sep 17 00:00:00 2001 From: NewFuture Date: Fri, 28 Oct 2016 09:31:00 +0800 Subject: [PATCH 2/2] add example --- examples/host-port/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/host-port/README.md b/examples/host-port/README.md index 7c1303f273..7f52f0a908 100644 --- a/examples/host-port/README.md +++ b/examples/host-port/README.md @@ -1,13 +1,19 @@ # host and port +Only For ipv4 ```shell node ../../bin/webpack-dev-server.js --open --port 5000 --host 0.0.0.0 ``` +For ipv6 support. (it also works with ipv4.) +```shell +node ../../bin/webpack-dev-server.js --open --port 5000 --host :: +``` + We want to change the port to `5000`, and make the server publicly accessible. ## What should happen -The script should open `http://0.0.0.0:5000/`. You should see "It's working." +The script should open `http://0.0.0.0:5000/`(ipv4) or `http://[::]:5000/`(ipv6). You should see "It's working." Get your local ip (e.g. `192.168.1.40`), and try it from `192.168.1.40:5000`. Make sure your firewall doesn't block this port.