From 4f1c37b7bc4d989454518cfcbbd5815713099b6a Mon Sep 17 00:00:00 2001 From: Charles Lyding Date: Wed, 17 May 2017 22:53:02 -0400 Subject: [PATCH] fix(@angular/cli): allow public host option to accept only hostname --- packages/@angular/cli/tasks/serve.ts | 11 ++++++----- tests/e2e/tests/misc/public-host.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/@angular/cli/tasks/serve.ts b/packages/@angular/cli/tasks/serve.ts index c158c83090eb..84adb97cd6f7 100644 --- a/packages/@angular/cli/tasks/serve.ts +++ b/packages/@angular/cli/tasks/serve.ts @@ -60,12 +60,13 @@ export default Task.extend({ let clientAddress = serverAddress; if (serveTaskOptions.publicHost) { - const clientUrl = url.parse(serveTaskOptions.publicHost); - // very basic sanity check - if (!clientUrl.host) { - return Promise.reject(new SilentError(`'live-reload-client' must be a full URL.`)); + let publicHost = serveTaskOptions.publicHost; + if (!/^\w+:\/\//.test(publicHost)) { + publicHost = `${serveTaskOptions.ssl ? 'https' : 'http'}://${publicHost}`; } - clientAddress = clientUrl.href; + const clientUrl = url.parse(publicHost); + serveTaskOptions.publicHost = clientUrl.host; + clientAddress = url.format(clientUrl); } if (serveTaskOptions.liveReload) { diff --git a/tests/e2e/tests/misc/public-host.ts b/tests/e2e/tests/misc/public-host.ts index c566841d5c1d..d8b17cff8fe4 100644 --- a/tests/e2e/tests/misc/public-host.ts +++ b/tests/e2e/tests/misc/public-host.ts @@ -39,5 +39,21 @@ export default function () { throw new Error('Response does not match expected value.'); } }) + .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) + .then(() => ngServe('--host=0.0.0.0', `--public-host=${localAddress}`)) + .then(() => request(localAddress)) + .then(body => { + if (!body.match(/<\/app-root>/)) { + throw new Error('Response does not match expected value.'); + } + }) + .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) + .then(() => ngServe('--host=0.0.0.0', `--public-host=${firstLocalIp}`)) + .then(() => request(localAddress)) + .then(body => { + if (!body.match(/<\/app-root>/)) { + throw new Error('Response does not match expected value.'); + } + }) .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }); }