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

Fixed ipv6 [::] #676

Merged
merged 2 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion examples/host-port/README.md
Original file line number Diff line number Diff line change
@@ -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.