Skip to content

Commit 80e3d46

Browse files
clydinmgechev
authored andcommitted
fix(@angular-devkit/build-angular): ensure correct dev server path with public host option
1 parent 2a144a9 commit 80e3d46

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
9090
}
9191

9292
// Resolve public host and client address.
93-
let clientAddress = `${options.ssl ? 'https' : 'http'}://0.0.0.0:0`;
93+
let clientAddress = url.parse(`${options.ssl ? 'https' : 'http'}://0.0.0.0:0`);
9494
if (options.publicHost) {
9595
let publicHost = options.publicHost;
9696
if (!/^\w+:\/\//.test(publicHost)) {
9797
publicHost = `${options.ssl ? 'https' : 'http'}://${publicHost}`;
9898
}
99-
const clientUrl = url.parse(publicHost);
100-
options.publicHost = clientUrl.host;
101-
clientAddress = url.format(clientUrl);
99+
clientAddress = url.parse(publicHost);
100+
options.publicHost = clientAddress.host;
102101
}
103102

104103
// Resolve serve address.
@@ -250,7 +249,7 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
250249
options: DevServerBuilderOptions,
251250
browserOptions: NormalizedBrowserBuilderSchema,
252251
webpackConfig: any, // tslint:disable-line:no-any
253-
clientAddress: string,
252+
clientAddress: url.UrlWithStringQuery,
254253
) {
255254
// This allows for live reload of page when changes are made to repo.
256255
// https://webpack.js.org/configuration/dev-server/#devserver-inline
@@ -260,7 +259,14 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
260259
} catch {
261260
throw new Error('The "webpack-dev-server" package could not be found.');
262261
}
263-
const entryPoints = [`${webpackDevServerPath}?${clientAddress}`];
262+
263+
// If a custom path is provided the webpack dev server client drops the sockjs-node segment.
264+
// This adds it back so that behavior is consistent when using a custom URL path
265+
if (clientAddress.pathname) {
266+
clientAddress.pathname = path.posix.join(clientAddress.pathname, 'sockjs-node');
267+
}
268+
269+
const entryPoints = [`${webpackDevServerPath}?${url.format(clientAddress)}`];
264270
if (options.hmr) {
265271
const webpackHmrLink = 'https://webpack.js.org/guides/hot-module-replacement';
266272

0 commit comments

Comments
 (0)