Skip to content

Commit

Permalink
fix: scriptHost in client (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev authored and evilebottnawi committed Sep 16, 2019
1 parent 5f9dde9 commit 00903f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client-src/default/utils/createSocketUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ function createSocketUrl(resourceQuery) {
// Else, get the url from the <script> this file was called with.
let scriptHost = getCurrentScriptSource();

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

Expand Down
4 changes: 4 additions & 0 deletions test/client/utils/__snapshots__/createSocketUrl.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ exports[`createSocketUrl should return the url when __resourceQuery is https://e

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

exports[`createSocketUrl should return the url when __resourceQuery is undefined 1`] = `"/sockjs-node"`;

exports[`createSocketUrl should return the url when the current script source is ?test 1`] = `"/sockjs-node"`;

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

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

exports[`createSocketUrl should return the url when the current script source is undefined 1`] = `"/sockjs-node"`;
2 changes: 2 additions & 0 deletions test/client/utils/createSocketUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('createSocketUrl', () => {
// TODO: comment out after the major release
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
// 'file://filename',
// eslint-disable-next-line no-undefined
undefined,
];

samples.forEach((url) => {
Expand Down

0 comments on commit 00903f6

Please sign in to comment.