Skip to content

Commit 717880f

Browse files
svsoolSpaceK33z
authored andcommitted
fix hostname resolving when using something like Electron (#594)
1 parent 02db200 commit 717880f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

client/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,21 @@ var onSocketMsg = {
8888
}
8989
};
9090

91+
var hostname = urlParts.hostname;
92+
93+
if(urlParts.hostname === '0.0.0.0') {
94+
// why do we need this check?
95+
// hostname n/a for file protocol (example, when using electron, ionic)
96+
// see: https://github.com/webpack/webpack-dev-server/pull/384
97+
if(window.location.hostname && !!~window.location.protocol.indexOf('http')) {
98+
hostname = window.location.hostname;
99+
}
100+
}
101+
91102
var socketUrl = url.format({
92103
protocol: (window.location.protocol === "https:" || urlParts.hostname === '0.0.0.0') ? window.location.protocol : urlParts.protocol,
93104
auth: urlParts.auth,
94-
hostname: (urlParts.hostname === '0.0.0.0') ? window.location.hostname : urlParts.hostname,
105+
hostname: hostname,
95106
port: (urlParts.port === '0') ? window.location.port : urlParts.port,
96107
pathname: urlParts.path == null || urlParts.path === '/' ? "/sockjs-node" : urlParts.path
97108
});

0 commit comments

Comments
 (0)