Skip to content

Commit 3f1ee2c

Browse files
committed
fix(@angular-devkit/build-angular): ensure correct dev server path with public host option
If a custom path is provided the webpack dev server client drops the sockjs-node segment. This adds it back so that behavior is consistent when using a custom URL path. Fixes #13627
1 parent 7915a58 commit 3f1ee2c

File tree

1 file changed

+12
-6
lines changed
  • packages/angular_devkit/build_angular/src/dev-server

1 file changed

+12
-6
lines changed

packages/angular_devkit/build_angular/src/dev-server/index.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ export function serveWebpackBrowser(
144144
options.port = port;
145145

146146
// Resolve public host and client address.
147-
let clientAddress = `${options.ssl ? 'https' : 'http'}://0.0.0.0:0`;
147+
let clientAddress = url.parse(`${options.ssl ? 'https' : 'http'}://0.0.0.0:0`);
148148
if (options.publicHost) {
149149
let publicHost = options.publicHost;
150150
if (!/^\w+:\/\//.test(publicHost)) {
151151
publicHost = `${options.ssl ? 'https' : 'http'}://${publicHost}`;
152152
}
153-
const clientUrl = url.parse(publicHost);
154-
options.publicHost = clientUrl.host;
155-
clientAddress = url.format(clientUrl);
153+
clientAddress = url.parse(publicHost);
154+
options.publicHost = clientAddress.host;
156155
}
157156

158157
// Resolve serve address.
@@ -338,7 +337,7 @@ function _addLiveReload(
338337
options: DevServerBuilderSchema,
339338
browserOptions: BrowserBuilderSchema,
340339
webpackConfig: webpack.Configuration,
341-
clientAddress: string,
340+
clientAddress: url.UrlWithStringQuery,
342341
logger: logging.LoggerApi,
343342
) {
344343
if (webpackConfig.plugins === undefined) {
@@ -353,7 +352,14 @@ function _addLiveReload(
353352
} catch {
354353
throw new Error('The "webpack-dev-server" package could not be found.');
355354
}
356-
const entryPoints = [`${webpackDevServerPath}?${clientAddress}`];
355+
356+
// If a custom path is provided the webpack dev server client drops the sockjs-node segment.
357+
// This adds it back so that behavior is consistent when using a custom URL path
358+
if (clientAddress.pathname) {
359+
clientAddress.pathname = path.posix.join(clientAddress.pathname, 'sockjs-node');
360+
}
361+
362+
const entryPoints = [`${webpackDevServerPath}?${url.format(clientAddress)}`];
357363
if (options.hmr) {
358364
const webpackHmrLink = 'https://webpack.js.org/guides/hot-module-replacement';
359365

0 commit comments

Comments
 (0)