Skip to content

Commit

Permalink
Merge pull request #469 from shulhi/feature-custom-server-address
Browse files Browse the repository at this point in the history
Added feature to customize server address in console
  • Loading branch information
tommy351 committed Feb 5, 2014
2 parents 8c4b9b7 + b510e8c commit 54e4f5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion assets/init/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -96,4 +97,4 @@ markdown:
# Deployment
## Docs: http://zespia.tw/hexo/docs/deployment.html
deploy:
type:
type:
3 changes: 2 additions & 1 deletion lib/plugins/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'},
Expand All @@ -111,4 +112,4 @@ var publishOptions = {
]
};

console.register('publish', 'Publish a draft', publishOptions, require('./publish'));
console.register('publish', 'Publish a draft', publishOptions, require('./publish'));
12 changes: 8 additions & 4 deletions lib/plugins/console/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -99,4 +103,4 @@ module.exports = function(args, callback){
hexo.emit('server');
});
});
};
};

0 comments on commit 54e4f5d

Please sign in to comment.