Skip to content

feat: add host flag support for ng serve #1442

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
Jul 25, 2016
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
4 changes: 2 additions & 2 deletions addon/ng2/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = Command.extend({

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

commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host;
Expand Down
8 changes: 4 additions & 4 deletions addon/ng2/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { CliConfig } from '../models/config';

module.exports = Task.extend({
run: function(commandOptions: ServeTaskOptions) {

let lastHash = null;
let webpackCompiler: any;

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

webpackCompiler.apply(new ProgressPlugin({
Expand All @@ -33,11 +33,11 @@ module.exports = Task.extend({
inline: true
};

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

return new Promise((resolve, reject) => {
server.listen(commandOptions.port, 'localhost', function(err, stats) {
server.listen(commandOptions.port, `${commandOptions.host}`, function(err, stats) {
if(err) {
lastHash = null;
console.error(err.stack || err);
Expand Down