From c5ba23535465ea73f5d900936109dc961b07fe2a Mon Sep 17 00:00:00 2001 From: Su-Au Hwang Date: Sun, 16 Oct 2016 18:09:50 +0800 Subject: [PATCH 1/5] Feature: Allow content to be served from virtual host path e.g. http://example.com/admin/ --- packages/angular-cli/commands/serve.ts | 7 +++++++ packages/angular-cli/custom-typings.d.ts | 2 +- packages/angular-cli/tasks/serve-webpack.ts | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/angular-cli/commands/serve.ts b/packages/angular-cli/commands/serve.ts index c30e5520f222..12f01bf0e259 100644 --- a/packages/angular-cli/commands/serve.ts +++ b/packages/angular-cli/commands/serve.ts @@ -27,6 +27,7 @@ export interface ServeTaskOptions { sslCert?: string; aot?: boolean; open?: boolean; + path?: string; } const ServeCommand = Command.extend({ @@ -88,6 +89,12 @@ const ServeCommand = Command.extend({ aliases: ['o'], description: 'Opens the url in default browser', }, + { + name: 'path', + type: String, + default: '/', + description: 'makes the content available on path e.g. http://host:port/path' + }, ], run: function(commandOptions: ServeTaskOptions) { diff --git a/packages/angular-cli/custom-typings.d.ts b/packages/angular-cli/custom-typings.d.ts index 1fbb264de74a..4f86ad25c328 100644 --- a/packages/angular-cli/custom-typings.d.ts +++ b/packages/angular-cli/custom-typings.d.ts @@ -1,7 +1,7 @@ interface IWebpackDevServerConfigurationOptions { contentBase?: string; hot?: boolean; - historyApiFallback?: boolean; + historyApiFallback?: boolean | {[key:string]: string}; compress?: boolean; proxy?: {[key: string]: string}; staticOptions?: any; diff --git a/packages/angular-cli/tasks/serve-webpack.ts b/packages/angular-cli/tasks/serve-webpack.ts index 42d16c9c4712..f1fafae6b713 100644 --- a/packages/angular-cli/tasks/serve-webpack.ts +++ b/packages/angular-cli/tasks/serve-webpack.ts @@ -57,13 +57,16 @@ export default Task.extend({ this.project.root, `./${CliConfig.fromProject().config.apps[0].root}` ), - historyApiFallback: true, + historyApiFallback: { + index: commandOptions.path + }, stats: webpackDevServerOutputOptions, inline: true, proxy: proxyConfig, watchOptions: { poll: CliConfig.fromProject().config.defaults.poll - } + }, + publicPath: commandOptions.path, }; ui.writeLine(chalk.green(oneLine` From 76e0465108dace5840f235bfce5f0040ace951bf Mon Sep 17 00:00:00 2001 From: Su-Au Hwang Date: Mon, 17 Oct 2016 17:40:48 +0800 Subject: [PATCH 2/5] Fix tslint error --- packages/angular-cli/custom-typings.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/angular-cli/custom-typings.d.ts b/packages/angular-cli/custom-typings.d.ts index 4f86ad25c328..668bf95c4aca 100644 --- a/packages/angular-cli/custom-typings.d.ts +++ b/packages/angular-cli/custom-typings.d.ts @@ -1,7 +1,7 @@ interface IWebpackDevServerConfigurationOptions { contentBase?: string; hot?: boolean; - historyApiFallback?: boolean | {[key:string]: string}; + historyApiFallback?: boolean | { [key: string]: string }; compress?: boolean; proxy?: {[key: string]: string}; staticOptions?: any; From 7a92b064fe9e735d5d05f777cd99a7a9a30cb0bd Mon Sep 17 00:00:00 2001 From: Su-Au Hwang Date: Wed, 26 Oct 2016 05:18:35 +0800 Subject: [PATCH 3/5] Rename --path option for ng serve command to --base-href (alias --bh). This option now also sets the base-href tag in index.html to match the virtual path. --- packages/angular-cli/commands/serve.ts | 10 +++++----- packages/angular-cli/tasks/serve-webpack.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/angular-cli/commands/serve.ts b/packages/angular-cli/commands/serve.ts index 9e230100e5a0..bb3a6a09140b 100644 --- a/packages/angular-cli/commands/serve.ts +++ b/packages/angular-cli/commands/serve.ts @@ -27,7 +27,7 @@ export interface ServeTaskOptions { sslCert?: string; aot?: boolean; open?: boolean; - path?: string; + baseHref?: string; } const ServeCommand = Command.extend({ @@ -89,12 +89,12 @@ const ServeCommand = Command.extend({ aliases: ['o'], description: 'Opens the url in default browser', }, - { - name: 'path', + { name: 'base-href', type: String, - default: '/', + default: null, + aliases: ['bh'], description: 'makes the content available on path e.g. http://host:port/path' - }, + } ], run: function(commandOptions: ServeTaskOptions) { diff --git a/packages/angular-cli/tasks/serve-webpack.ts b/packages/angular-cli/tasks/serve-webpack.ts index 867d61e5ed25..051f855b1f09 100644 --- a/packages/angular-cli/tasks/serve-webpack.ts +++ b/packages/angular-cli/tasks/serve-webpack.ts @@ -25,7 +25,7 @@ export default Task.extend({ commandOptions.target, commandOptions.environment, undefined, - undefined, + commandOptions.baseHref, commandOptions.aot ).config; @@ -71,7 +71,7 @@ export default Task.extend({ `./${CliConfig.fromProject().config.apps[0].root}` ), historyApiFallback: { - index: commandOptions.path, + index: commandOptions.baseHref, disableDotRule: true }, stats: webpackDevServerOutputOptions, @@ -82,7 +82,7 @@ export default Task.extend({ poll: CliConfig.fromProject().config.defaults.poll }, https: commandOptions.ssl, - publicPath: commandOptions.path + publicPath: commandOptions.baseHref }; if (sslKey != null && sslCert != null) { From d2fc15a432580b544dcd6b7a9e7beb8a3383acb8 Mon Sep 17 00:00:00 2001 From: Su-Au Hwang Date: Sat, 19 Nov 2016 11:04:27 +0800 Subject: [PATCH 4/5] Add e2e test for serve --base-href option. WARNING: This test should fail, but it doesn't. --- tests/e2e/tests/test/e2e.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/tests/test/e2e.ts b/tests/e2e/tests/test/e2e.ts index ca66091906c7..a290d69aff25 100644 --- a/tests/e2e/tests/test/e2e.ts +++ b/tests/e2e/tests/test/e2e.ts @@ -19,5 +19,6 @@ export default function() { .then(() => _runServeAndE2e()) .then(() => _runServeAndE2e('--prod')) .then(() => _runServeAndE2e('--aot')) - .then(() => _runServeAndE2e('--aot', '--prod')); + .then(() => _runServeAndE2e('--aot', '--prod')) + .then(() => _runServeAndE2e('--base-href /test-base-href/')); } From 0bfd9ca840169621d053bd9ccf35e33d2ad3f37f Mon Sep 17 00:00:00 2001 From: Su-Au Hwang Date: Tue, 22 Nov 2016 12:56:41 +0800 Subject: [PATCH 5/5] Add --base-href e2e tests with expected fail and spec changes to make it pass --- tests/e2e/tests/test/e2e.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/e2e/tests/test/e2e.ts b/tests/e2e/tests/test/e2e.ts index a290d69aff25..7cb9d7a619e3 100644 --- a/tests/e2e/tests/test/e2e.ts +++ b/tests/e2e/tests/test/e2e.ts @@ -1,6 +1,7 @@ import {ng, killAllProcesses} from '../../utils/process'; import {expectToFail} from '../../utils/utils'; import {ngServe} from '../../utils/project'; +import {replaceInFile} from "../../utils/fs"; function _runServeAndE2e(...args: string[]) { @@ -20,5 +21,11 @@ export default function() { .then(() => _runServeAndE2e('--prod')) .then(() => _runServeAndE2e('--aot')) .then(() => _runServeAndE2e('--aot', '--prod')) + // this should fail because we haven't changed the e2e test yet + .then(() => expectToFail(() => _runServeAndE2e('--base-href /test-base-href/'))) + .then(() => replaceInFile('e2e/app.po.ts', + 'browser.get(\'/\');', + 'browser.get(\'/test-base-href/\');')) + // now it should pass .then(() => _runServeAndE2e('--base-href /test-base-href/')); }