Skip to content

fix(@angular/cli): allow public host option to accept only hostname #6367

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

Merged
merged 1 commit into from Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; });
}