forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): add host check flags to ng serve
Two new flags are added to `ng serve`: - `--public-host` (aliased by `--live-reload-client): Specify the URL that the browser client will use. - `--disable-host-check`: Don't verify connected clients are part of allowed hosts. Setting `--disable-host-check` will output a warning: ``` WARNING Running a server with --disable-host-check is a security risk. See https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a for more information. ``` See angular#6070 for more context about this change. Fix angular#6070
- Loading branch information
1 parent
a3bf529
commit 759a023
Showing
8 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as os from 'os'; | ||
import * as _ from 'lodash'; | ||
|
||
import { request } from '../../utils/http'; | ||
import { killAllProcesses } from '../../utils/process'; | ||
import { ngServe } from '../../utils/project'; | ||
|
||
export default function () { | ||
const firstLocalIp = _(os.networkInterfaces()) | ||
.values() | ||
.flatten() | ||
.filter({ family: 'IPv4', internal: false }) | ||
.map('address') | ||
.first(); | ||
const publicHost = `${firstLocalIp}:4200`; | ||
const localAddress = `http://${publicHost}`; | ||
|
||
return Promise.resolve() | ||
.then(() => ngServe('--host=0.0.0.0')) | ||
.then(() => request(localAddress)) | ||
.then(body => { | ||
if (!body.match(/Invalid Host header/)) { | ||
throw new Error('Response does not match expected value.'); | ||
} | ||
}) | ||
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) | ||
.then(() => ngServe('--host=0.0.0.0', `--public-host=${publicHost}`)) | ||
.then(() => request(localAddress)) | ||
.then(body => { | ||
if (!body.match(/<app-root>Loading...<\/app-root>/)) { | ||
throw new Error('Response does not match expected value.'); | ||
} | ||
}) | ||
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) | ||
.then(() => ngServe('--host=0.0.0.0', `--disable-host-check`)) | ||
.then(() => request(localAddress)) | ||
.then(body => { | ||
if (!body.match(/<app-root>Loading...<\/app-root>/)) { | ||
throw new Error('Response does not match expected value.'); | ||
} | ||
}) | ||
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }); | ||
} |