Skip to content
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

Added feature to customize server address in console #469

Merged
merged 4 commits into from
Feb 5, 2014
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
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');
});
});
};
};