Skip to content

Commit

Permalink
fix(@angular/cli): allow public host option to accept only hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Lyding authored and filipesilva committed Jun 7, 2017
1 parent 6a93451 commit 4f1c37b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/tests/misc/public-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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><\/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><\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
}

0 comments on commit 4f1c37b

Please sign in to comment.