Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command serve feature: Allow content to be served from virtual host path #2727

Closed
wants to merge 10 commits into from
7 changes: 7 additions & 0 deletions packages/angular-cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ServeTaskOptions {
aot?: boolean;
sourcemap?: boolean;
open?: boolean;
baseHref?: string;
}

const ServeCommand = Command.extend({
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default Task.extend({
commandOptions.target,
commandOptions.environment,
undefined,
undefined,
commandOptions.baseHref,
commandOptions.aot,
commandOptions.sourcemap
).config;
Expand Down Expand Up @@ -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']
},
Expand All @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion tests/e2e/tests/test/e2e.ts
Original file line number Diff line number Diff line change
@@ -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[]) {
Expand All @@ -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/'));
}