From 3224d5332f6fc4d0c28f9aad4c23579d0068e624 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Mon, 27 Jan 2014 01:53:56 +0800 Subject: [PATCH 1/3] added feature to customize server address in console --- assets/init/_config.yml | 3 ++- lib/plugins/console/index.js | 3 ++- lib/plugins/console/server.js | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/assets/init/_config.yml b/assets/init/_config.yml index 33db566399..95a514799f 100644 --- a/assets/init/_config.yml +++ b/assets/init/_config.yml @@ -58,6 +58,7 @@ tag: 2 ## You can customize the logger format as defined in ## http://www.senchalabs.org/connect/logger.html port: 4000 +server_address: localhost logger: false logger_format: @@ -96,4 +97,4 @@ markdown: # Deployment ## Docs: http://zespia.tw/hexo/docs/deployment.html deploy: - type: \ No newline at end of file + type: diff --git a/lib/plugins/console/index.js b/lib/plugins/console/index.js index 45c7d46086..4dbee66cc3 100644 --- a/lib/plugins/console/index.js +++ b/lib/plugins/console/index.js @@ -87,6 +87,7 @@ var serverOptions = { alias: 's', desc: 'Start the server and watch for file changes.', options: [ + {name: '-a, --address', desc: 'Override the default server address. Default is localhost'}, {name: '-p, --port', desc: 'Override the default port'}, {name: '-s, --static', desc: 'Only serve static files'}, {name: '-l, --log [format]', desc: 'Enable logger. Override the logger format.'}, @@ -111,4 +112,4 @@ var publishOptions = { ] }; -console.register('publish', 'Publish a draft', publishOptions, require('./publish')); \ No newline at end of file +console.register('publish', 'Publish a draft', publishOptions, require('./publish')); diff --git a/lib/plugins/console/server.js b/lib/plugins/console/server.js index efb852593e..7dc5844660 100644 --- a/lib/plugins/console/server.js +++ b/lib/plugins/console/server.js @@ -9,6 +9,7 @@ module.exports = function(args, callback){ processor = hexo.extend.processor; var app = express(), + serverAddress = args.a || args.address || config.server_address || 'localhost', port = parseInt(args.p || args.port || config.port, 10) || 4000, useDrafts = args.d || args.drafts || config.render_drafts || false, loggerFormat = args.l || args.log, @@ -87,7 +88,7 @@ module.exports = function(args, callback){ if (useDrafts) log.i('Using drafts.'); - log.i('Hexo is running at ' + 'localhost:%d%s'.underline + '. Press Ctrl+C to stop.', port, root); + log.i('Hexo is running at ' + '%s:%d%s'.underline + '. Press Ctrl+C to stop.', serverAddress, port, root); /** * Fired after server started. @@ -99,4 +100,4 @@ module.exports = function(args, callback){ hexo.emit('server'); }); }); -}; \ No newline at end of file +}; From 3646e219cb780a3a4e015ea72aed7eb38c0a5ff3 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Mon, 27 Jan 2014 05:44:07 +0800 Subject: [PATCH 2/3] added ability to bind ip address --- lib/plugins/console/index.js | 2 +- lib/plugins/console/server.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/plugins/console/index.js b/lib/plugins/console/index.js index 4dbee66cc3..8f7dafe929 100644 --- a/lib/plugins/console/index.js +++ b/lib/plugins/console/index.js @@ -87,7 +87,7 @@ var serverOptions = { alias: 's', desc: 'Start the server and watch for file changes.', options: [ - {name: '-a, --address', desc: 'Override the default server address. Default is localhost'}, + {name: '-i, --ip', desc: 'Override the default server ip. Bind to all ip address by default'}, {name: '-p, --port', desc: 'Override the default port'}, {name: '-s, --static', desc: 'Only serve static files'}, {name: '-l, --log [format]', desc: 'Enable logger. Override the logger format.'}, diff --git a/lib/plugins/console/server.js b/lib/plugins/console/server.js index 7dc5844660..3e3bd05c27 100644 --- a/lib/plugins/console/server.js +++ b/lib/plugins/console/server.js @@ -9,7 +9,7 @@ module.exports = function(args, callback){ processor = hexo.extend.processor; var app = express(), - serverAddress = args.a || args.address || config.server_address || 'localhost', + serverIp = args.i || args.ip || config.server_ip || '0.0.0.0', port = parseInt(args.p || args.port || config.port, 10) || 4000, useDrafts = args.d || args.drafts || config.render_drafts || false, loggerFormat = args.l || args.log, @@ -84,11 +84,14 @@ module.exports = function(args, callback){ if (err) return callback(err); // Start listening! - app.listen(port, function(){ + app.listen(port, serverIp, function(){ if (useDrafts) log.i('Using drafts.'); - - log.i('Hexo is running at ' + '%s:%d%s'.underline + '. Press Ctrl+C to stop.', serverAddress, port, root); + + // for display purpose only + var ip = ''; + (serverIp == '0.0.0.0') ? ip = 'localhost' : ip = serverIp; + log.i('Hexo is running at ' + 'http:\/\/%s:%d%s'.underline + '. Press Ctrl+C to stop.', ip, port, root); /** * Fired after server started. From 6c6c554dcfab2474f5ec1d6bfa0c2e37e25773dc Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Mon, 27 Jan 2014 05:44:07 +0800 Subject: [PATCH 3/3] added ability to bind ip address --- assets/init/_config.yml | 2 +- lib/plugins/console/index.js | 2 +- lib/plugins/console/server.js | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/assets/init/_config.yml b/assets/init/_config.yml index 95a514799f..22d0a2351a 100644 --- a/assets/init/_config.yml +++ b/assets/init/_config.yml @@ -58,7 +58,7 @@ tag: 2 ## You can customize the logger format as defined in ## http://www.senchalabs.org/connect/logger.html port: 4000 -server_address: localhost +server_ip: 0.0.0.0 # bind to all ip address by default logger: false logger_format: diff --git a/lib/plugins/console/index.js b/lib/plugins/console/index.js index 4dbee66cc3..8f7dafe929 100644 --- a/lib/plugins/console/index.js +++ b/lib/plugins/console/index.js @@ -87,7 +87,7 @@ var serverOptions = { alias: 's', desc: 'Start the server and watch for file changes.', options: [ - {name: '-a, --address', desc: 'Override the default server address. Default is localhost'}, + {name: '-i, --ip', desc: 'Override the default server ip. Bind to all ip address by default'}, {name: '-p, --port', desc: 'Override the default port'}, {name: '-s, --static', desc: 'Only serve static files'}, {name: '-l, --log [format]', desc: 'Enable logger. Override the logger format.'}, diff --git a/lib/plugins/console/server.js b/lib/plugins/console/server.js index 7dc5844660..3e3bd05c27 100644 --- a/lib/plugins/console/server.js +++ b/lib/plugins/console/server.js @@ -9,7 +9,7 @@ module.exports = function(args, callback){ processor = hexo.extend.processor; var app = express(), - serverAddress = args.a || args.address || config.server_address || 'localhost', + serverIp = args.i || args.ip || config.server_ip || '0.0.0.0', port = parseInt(args.p || args.port || config.port, 10) || 4000, useDrafts = args.d || args.drafts || config.render_drafts || false, loggerFormat = args.l || args.log, @@ -84,11 +84,14 @@ module.exports = function(args, callback){ if (err) return callback(err); // Start listening! - app.listen(port, function(){ + app.listen(port, serverIp, function(){ if (useDrafts) log.i('Using drafts.'); - - log.i('Hexo is running at ' + '%s:%d%s'.underline + '. Press Ctrl+C to stop.', serverAddress, port, root); + + // for display purpose only + var ip = ''; + (serverIp == '0.0.0.0') ? ip = 'localhost' : ip = serverIp; + log.i('Hexo is running at ' + 'http:\/\/%s:%d%s'.underline + '. Press Ctrl+C to stop.', ip, port, root); /** * Fired after server started.