Skip to content

Commit d21148b

Browse files
committed
Fix invalid url for websocket when using a relative path and https
Ref #592
1 parent 717880f commit d21148b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

client/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ var onSocketMsg = {
8989
};
9090

9191
var hostname = urlParts.hostname;
92+
var protocol = urlParts.protocol;
9293

9394
if(urlParts.hostname === '0.0.0.0') {
9495
// why do we need this check?
@@ -99,8 +100,16 @@ if(urlParts.hostname === '0.0.0.0') {
99100
}
100101
}
101102

103+
// `hostname` can be empty when the script path is relative. In that case, specifying
104+
// a protocol would result in an invalid URL.
105+
// When https is used in the app, secure websockets are always necessary
106+
// because the browser doesn't accept non-secure websockets.
107+
if(hostname && (window.location.protocol === "https:" || urlParts.hostname === '0.0.0.0')) {
108+
protocol = window.location.protocol;
109+
}
110+
102111
var socketUrl = url.format({
103-
protocol: (window.location.protocol === "https:" || urlParts.hostname === '0.0.0.0') ? window.location.protocol : urlParts.protocol,
112+
protocol: protocol,
104113
auth: urlParts.auth,
105114
hostname: hostname,
106115
port: (urlParts.port === '0') ? window.location.port : urlParts.port,

examples/modus-manual-script/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Modus: manual script
22

33
```shell
4-
node ../../bin/webpack-dev-server.js --open
4+
node ../../bin/webpack-dev-server.js --open --no-inline
55
```
66

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

99
```shell
10-
node ../../bin/webpack-dev-server.js --open --https
10+
node ../../bin/webpack-dev-server.js --open --no-inline --https
1111
```
1212

1313
This will do the same, but connect over https.

0 commit comments

Comments
 (0)