diff --git a/assets/init/_config.yml b/assets/init/_config.yml index 33db566399..22d0a2351a 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_ip: 0.0.0.0 # bind to all ip address by default 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..8f7dafe929 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: '-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.'}, @@ -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..3e3bd05c27 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(), + 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, @@ -83,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 ' + 'localhost:%d%s'.underline + '. Press Ctrl+C to stop.', 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. @@ -99,4 +103,4 @@ module.exports = function(args, callback){ hexo.emit('server'); }); }); -}; \ No newline at end of file +};