Skip to content

Commit 930785f

Browse files
TheLarkInnfilipesilva
authored andcommitted
feat: add host flag support for ng serve (#1442)
1 parent b8f502e commit 930785f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

addon/ng2/commands/serve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = Command.extend({
3737

3838
availableOptions: [
3939
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
40-
{ name: 'host', type: String, aliases: ['H'], description: 'Listens on all interfaces by default' },
40+
{ name: 'host', type: String, default: 'localhost', aliases: ['H'], description: 'Listens on all interfaces by default' },
4141
{ name: 'proxy', type: String, aliases: ['pr', 'pxy'] },
4242
{ name: 'insecure-proxy', type: Boolean, default: false, aliases: ['inspr'], description: 'Set false to proxy self-signed SSL certificates' },
4343
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
@@ -61,7 +61,7 @@ module.exports = Command.extend({
6161
}
6262
if (commandOptions.target === 'production') {
6363
commandOptions.environment = 'prod';
64-
}
64+
}
6565
}
6666

6767
commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host;

addon/ng2/tasks/serve-webpack.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import { CliConfig } from '../models/config';
1111

1212
module.exports = Task.extend({
1313
run: function(commandOptions: ServeTaskOptions) {
14-
14+
1515
let lastHash = null;
1616
let webpackCompiler: any;
1717

1818
var config: NgCliWebpackConfig = new NgCliWebpackConfig(this.project, commandOptions.target, commandOptions.environment).config;
1919
// This allows for live reload of page when changes are made to repo.
2020
// https://webpack.github.io/docs/webpack-dev-server.html#inline-mode
21-
config.entry.main.unshift(`webpack-dev-server/client?http://localhost:${commandOptions.port}/`);
21+
config.entry.main.unshift(`webpack-dev-server/client?http://${commandOptions.host}:${commandOptions.port}/`);
2222
webpackCompiler = webpack(config);
2323

2424
webpackCompiler.apply(new ProgressPlugin({
@@ -33,11 +33,11 @@ module.exports = Task.extend({
3333
inline: true
3434
};
3535

36-
const serveMessage:string = chalk.green(`\n*\n*\n NG Live Development Server is running on http://localhost:${commandOptions.port}.\n*\n*`);
36+
const serveMessage:string = chalk.green(`\n*\n*\n NG Live Development Server is running on http://${commandOptions.host}:${commandOptions.port}.\n*\n*`);
3737
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
3838

3939
return new Promise((resolve, reject) => {
40-
server.listen(commandOptions.port, 'localhost', function(err, stats) {
40+
server.listen(commandOptions.port, `${commandOptions.host}`, function(err, stats) {
4141
if(err) {
4242
lastHash = null;
4343
console.error(err.stack || err);

0 commit comments

Comments
 (0)