diff --git a/packages/angular-cli/commands/serve.ts b/packages/angular-cli/commands/serve.ts index 4b19b651edb1..0a1b4e08ae20 100644 --- a/packages/angular-cli/commands/serve.ts +++ b/packages/angular-cli/commands/serve.ts @@ -28,6 +28,7 @@ export interface ServeTaskOptions { aot?: boolean; sourcemap?: boolean; open?: boolean; + baseHref?: string; } const ServeCommand = Command.extend({ @@ -90,6 +91,12 @@ const ServeCommand = Command.extend({ aliases: ['o'], description: 'Opens the url in default browser', }, + { name: 'base-href', + type: String, + 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 5f8a98980966..9d96472acaf7 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, commandOptions.sourcemap ).config; @@ -73,6 +73,7 @@ export default Task.extend({ ), headers: { 'Access-Control-Allow-Origin': '*' }, historyApiFallback: { + index: commandOptions.baseHref, disableDotRule: true, htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'] }, @@ -83,7 +84,8 @@ export default Task.extend({ watchOptions: { poll: CliConfig.fromProject().config.defaults.poll }, - https: commandOptions.ssl + https: commandOptions.ssl, + publicPath: commandOptions.baseHref }; if (sslKey != null && sslCert != null) { diff --git a/tests/e2e/tests/test/e2e.ts b/tests/e2e/tests/test/e2e.ts index ca66091906c7..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[]) { @@ -19,5 +20,12 @@ export default function() { .then(() => _runServeAndE2e()) .then(() => _runServeAndE2e('--prod')) .then(() => _runServeAndE2e('--aot')) - .then(() => _runServeAndE2e('--aot', '--prod')); + .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/')); }