From 5786897d4bc9ffa62de1b4ee940169748d9af0e1 Mon Sep 17 00:00:00 2001 From: NewFuture Date: Thu, 27 Oct 2016 23:11:12 +0800 Subject: [PATCH] fixed ipv6 ip parsing and listening at [::] --- bin/webpack-dev-server.js | 23 ++++++++++++++++------- client/index.js | 4 +++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index 3c43ce2df9..9940b4a849 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -272,8 +272,21 @@ function processOptions(wpOpt) { var protocol = options.https ? "https" : "http"; + /** + * the formated uri of the webpack server + */ + var uri = url.format({ + protocol: protocol, + hostname: options.host, + port: options.port.toString() + }); + if(options.inline !== false) { - var devClient = [require.resolve("../client/") + "?" + protocol + "://" + (options.public || (options.host + ":" + options.port))]; + /** + * client query url public or formated uri + */ + var query = options.public ? (protocol + "://" + options.public) : uri; + var devClient = [require.resolve("../client/") + "?" + query]; if(options.hotOnly) devClient.push("webpack/hot/only-dev-server"); @@ -302,12 +315,8 @@ function processOptions(wpOpt) { new Server(compiler, options).listen(options.port, options.host, function(err) { if(err) throw err; - var uri = url.format({ - protocol: protocol, - hostname: options.host, - port: options.port.toString(), - pathname: options.inline !== false ? "/" : "webpack-dev-server/" - }); + //add the pathname of uri + uri += options.inline !== false ? "/" : "webpack-dev-server/" console.log(" " + uri); console.log("webpack result is served from " + options.publicPath); 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