Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): ensure correct dev server path wi…
Browse files Browse the repository at this point in the history
…th public host option
  • Loading branch information
clydin authored and mgechev committed Mar 31, 2019
1 parent 2a144a9 commit 80e3d46
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/angular_devkit/build_angular/src/dev-server/index.ts
Expand Up @@ -90,15 +90,14 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
}

// Resolve public host and client address.
let clientAddress = `${options.ssl ? 'https' : 'http'}://0.0.0.0:0`;
let clientAddress = url.parse(`${options.ssl ? 'https' : 'http'}://0.0.0.0:0`);
if (options.publicHost) {
let publicHost = options.publicHost;
if (!/^\w+:\/\//.test(publicHost)) {
publicHost = `${options.ssl ? 'https' : 'http'}://${publicHost}`;
}
const clientUrl = url.parse(publicHost);
options.publicHost = clientUrl.host;
clientAddress = url.format(clientUrl);
clientAddress = url.parse(publicHost);
options.publicHost = clientAddress.host;
}

// Resolve serve address.
Expand Down Expand Up @@ -250,7 +249,7 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
options: DevServerBuilderOptions,
browserOptions: NormalizedBrowserBuilderSchema,
webpackConfig: any, // tslint:disable-line:no-any
clientAddress: string,
clientAddress: url.UrlWithStringQuery,
) {
// This allows for live reload of page when changes are made to repo.
// https://webpack.js.org/configuration/dev-server/#devserver-inline
Expand All @@ -260,7 +259,14 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
} catch {
throw new Error('The "webpack-dev-server" package could not be found.');
}
const entryPoints = [`${webpackDevServerPath}?${clientAddress}`];

// 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
if (clientAddress.pathname) {
clientAddress.pathname = path.posix.join(clientAddress.pathname, 'sockjs-node');
}

const entryPoints = [`${webpackDevServerPath}?${url.format(clientAddress)}`];
if (options.hmr) {
const webpackHmrLink = 'https://webpack.js.org/guides/hot-module-replacement';

Expand Down

0 comments on commit 80e3d46

Please sign in to comment.