diff --git a/packages/@angular/cli/tasks/serve.ts b/packages/@angular/cli/tasks/serve.ts index c91200a07a6d..a7d1c7bdacac 100644 --- a/packages/@angular/cli/tasks/serve.ts +++ b/packages/@angular/cli/tasks/serve.ts @@ -161,6 +161,11 @@ export default Task.extend({ webpackDevServerConfiguration.hot = serveTaskOptions.hmr; + // set publicPath property to be sent on webpack server config + if (serveTaskOptions.deployUrl) { + webpackDevServerConfiguration.publicPath = serveTaskOptions.deployUrl; + } + if (serveTaskOptions.target === 'production') { ui.writeLine(chalk.red(stripIndents` **************************************************************************************** diff --git a/tests/e2e/tests/misc/deploy-url.ts b/tests/e2e/tests/misc/deploy-url.ts new file mode 100644 index 000000000000..b43672e0eb84 --- /dev/null +++ b/tests/e2e/tests/misc/deploy-url.ts @@ -0,0 +1,18 @@ +import { killAllProcesses } from '../../utils/process'; +import { request } from '../../utils/http'; +import { expectToFail } from '../../utils/utils'; +import { ngServe } from '../../utils/project'; + +export default function () { + return Promise.resolve() + // check when setup through command line arguments + .then(() => ngServe('--deploy-url', '/deployurl', '--base-href', '/deployurl')) + .then(() => expectToFail(() => request('http://localhost:4200'))) + .then(() => request('http://localhost:4200/deployurl')) + .then(body => { + if (!body.match(/Loading...<\/app-root>/)) { + throw new Error('Response does not match expected value.'); + } + }) + .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }); +}