Skip to content

Commit 179bfb2

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 angular#13627
1 parent a1aa8d5 commit 179bfb2

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
@@ -73,15 +73,14 @@ export class DevServerBuilder implements Builder<DevServerBuilderSchema> {
7373
}
7474

7575
// Resolve public host and client address.
76-
let clientAddress = `${options.ssl ? 'https' : 'http'}://0.0.0.0:0`;
76+
let clientAddress = url.parse(`${options.ssl ? 'https' : 'http'}://0.0.0.0:0`);
7777
if (options.publicHost) {
7878
let publicHost = options.publicHost;
7979
if (!/^\w+:\/\//.test(publicHost)) {
8080
publicHost = `${options.ssl ? 'https' : 'http'}://${publicHost}`;
8181
}
82-
const clientUrl = url.parse(publicHost);
83-
options.publicHost = clientUrl.host;
84-
clientAddress = url.format(clientUrl);
82+
clientAddress = url.parse(publicHost);
83+
options.publicHost = clientAddress.host;
8584
}
8685

8786
// Resolve serve address.
@@ -233,7 +232,7 @@ export class DevServerBuilder implements Builder<DevServerBuilderSchema> {
233232
options: DevServerBuilderSchema,
234233
browserOptions: NormalizedBrowserBuilderSchema,
235234
webpackConfig: any, // tslint:disable-line:no-any
236-
clientAddress: string,
235+
clientAddress: url.UrlWithStringQuery,
237236
) {
238237
// This allows for live reload of page when changes are made to repo.
239238
// https://webpack.js.org/configuration/dev-server/#devserver-inline
@@ -243,7 +242,14 @@ export class DevServerBuilder implements Builder<DevServerBuilderSchema> {
243242
} catch {
244243
throw new Error('The "webpack-dev-server" package could not be found.');
245244
}
246-
const entryPoints = [`${webpackDevServerPath}?${clientAddress}`];
245+
246+
// If a custom path is provided the webpack dev server client drops the sockjs-node segment.
247+
// This adds it back so that behavior is consistent when using a custom URL path
248+
if (clientAddress.pathname) {
249+
clientAddress.pathname += path.posix.join(clientAddress.pathname, 'sockjs-node');
250+
}
251+
252+
const entryPoints = [`${webpackDevServerPath}?${url.format(clientAddress)}`];
247253
if (options.hmr) {
248254
const webpackHmrLink = 'https://webpack.js.org/guides/hot-module-replacement';
249255

0 commit comments

Comments
 (0)