Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4f1c37b

Browse files
Charles Lydingfilipesilva
Charles Lyding
authored andcommitted
fix(@angular/cli): allow public host option to accept only hostname
1 parent 6a93451 commit 4f1c37b

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

‎packages/@angular/cli/tasks/serve.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ export default Task.extend({
6060

6161
let clientAddress = serverAddress;
6262
if (serveTaskOptions.publicHost) {
63-
const clientUrl = url.parse(serveTaskOptions.publicHost);
64-
// very basic sanity check
65-
if (!clientUrl.host) {
66-
return Promise.reject(new SilentError(`'live-reload-client' must be a full URL.`));
63+
let publicHost = serveTaskOptions.publicHost;
64+
if (!/^\w+:\/\//.test(publicHost)) {
65+
publicHost = `${serveTaskOptions.ssl ? 'https' : 'http'}://${publicHost}`;
6766
}
68-
clientAddress = clientUrl.href;
67+
const clientUrl = url.parse(publicHost);
68+
serveTaskOptions.publicHost = clientUrl.host;
69+
clientAddress = url.format(clientUrl);
6970
}
7071

7172
if (serveTaskOptions.liveReload) {

‎tests/e2e/tests/misc/public-host.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,21 @@ export default function () {
3939
throw new Error('Response does not match expected value.');
4040
}
4141
})
42+
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; })
43+
.then(() => ngServe('--host=0.0.0.0', `--public-host=${localAddress}`))
44+
.then(() => request(localAddress))
45+
.then(body => {
46+
if (!body.match(/<app-root><\/app-root>/)) {
47+
throw new Error('Response does not match expected value.');
48+
}
49+
})
50+
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; })
51+
.then(() => ngServe('--host=0.0.0.0', `--public-host=${firstLocalIp}`))
52+
.then(() => request(localAddress))
53+
.then(body => {
54+
if (!body.match(/<app-root><\/app-root>/)) {
55+
throw new Error('Response does not match expected value.');
56+
}
57+
})
4258
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
4359
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /