Skip to content

Commit

Permalink
Fix invalid url for websocket when using a relative path and https
Browse files Browse the repository at this point in the history
Ref #592
  • Loading branch information
SpaceK33z committed Sep 6, 2016
1 parent 717880f commit d21148b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var onSocketMsg = {
};

var hostname = urlParts.hostname;
var protocol = urlParts.protocol;

if(urlParts.hostname === '0.0.0.0') {
// why do we need this check?
Expand All @@ -99,8 +100,16 @@ if(urlParts.hostname === '0.0.0.0') {
}
}

// `hostname` can be empty when the script path is relative. In that case, specifying
// a protocol would result in an invalid URL.
// When https is used in the app, secure websockets are always necessary
// because the browser doesn't accept non-secure websockets.
if(hostname && (window.location.protocol === "https:" || urlParts.hostname === '0.0.0.0')) {
protocol = window.location.protocol;
}

var socketUrl = url.format({
protocol: (window.location.protocol === "https:" || urlParts.hostname === '0.0.0.0') ? window.location.protocol : urlParts.protocol,
protocol: protocol,
auth: urlParts.auth,
hostname: hostname,
port: (urlParts.port === '0') ? window.location.port : urlParts.port,
Expand Down
4 changes: 2 additions & 2 deletions examples/modus-manual-script/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Modus: manual script

```shell
node ../../bin/webpack-dev-server.js --open
node ../../bin/webpack-dev-server.js --open --no-inline
```

The webpack-dev-server client is added as script tag to the html page.

```shell
node ../../bin/webpack-dev-server.js --open --https
node ../../bin/webpack-dev-server.js --open --no-inline --https
```

This will do the same, but connect over https.
Expand Down

0 comments on commit d21148b

Please sign in to comment.