Skip to content

Commit 00903f6

Browse files
knagaitsevevilebottnawi
authored andcommitted
fix: scriptHost in client (#2246)
1 parent 5f9dde9 commit 00903f6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

client-src/default/utils/createSocketUrl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ function createSocketUrl(resourceQuery) {
1616
// Else, get the url from the <script> this file was called with.
1717
let scriptHost = getCurrentScriptSource();
1818

19-
// eslint-disable-next-line no-useless-escape
20-
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
19+
if (scriptHost) {
20+
// eslint-disable-next-line no-useless-escape
21+
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
22+
}
2123
urlParts = url.parse(scriptHost || '/', false, true);
2224
}
2325

test/client/utils/__snapshots__/createSocketUrl.test.js.snap

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ exports[`createSocketUrl should return the url when __resourceQuery is https://e
1616

1717
exports[`createSocketUrl should return the url when __resourceQuery is https://localhost:123 1`] = `"ttps:localhost:123/sockjs-node"`;
1818

19+
exports[`createSocketUrl should return the url when __resourceQuery is undefined 1`] = `"/sockjs-node"`;
20+
1921
exports[`createSocketUrl should return the url when the current script source is ?test 1`] = `"/sockjs-node"`;
2022

2123
exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http:/sockjs-node"`;
@@ -31,3 +33,5 @@ exports[`createSocketUrl should return the url when the current script source is
3133
exports[`createSocketUrl should return the url when the current script source is https://example.com/path/foo.js 1`] = `"https://example.com/sockjs-node"`;
3234

3335
exports[`createSocketUrl should return the url when the current script source is https://localhost:123 1`] = `"https:/sockjs-node"`;
36+
37+
exports[`createSocketUrl should return the url when the current script source is undefined 1`] = `"/sockjs-node"`;

test/client/utils/createSocketUrl.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ describe('createSocketUrl', () => {
1313
// TODO: comment out after the major release
1414
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
1515
// 'file://filename',
16+
// eslint-disable-next-line no-undefined
17+
undefined,
1618
];
1719

1820
samples.forEach((url) => {

0 commit comments

Comments
 (0)