Permalink
Browse files

move default port to config

  • Loading branch information...
1 parent e458aca commit 64f602a5038dda50e394c35d7eb3fc6dc2f75dde @zhiyelee committed Nov 13, 2012
Showing with 38 additions and 7 deletions.
  1. +2 −2 README.md
  2. +18 −2 bin/cli.js
  3. +18 −3 lib/config.js
View
@@ -32,7 +32,7 @@ target_directory default to the current directory. The directory needs to exist,
mdserver serve [directory] [port]
starts a http server, that serves files from the directory.
-`directory` defaults to the current directory, `port` defaults to 3340
+`directory` defaults to the current directory, `port` defaults to `7878`
### module
@@ -42,7 +42,7 @@ var mdserver = require('mdserver');
mdserver.init(dir, [callback])
var handler = mdserver.handler(rootDir);
-http.createServer(handler).listen(3340);
+http.createServer(handler).listen(7878);
```
View
@@ -2,6 +2,7 @@
var http = require('http'),
path = require('path'),
init = require('../lib/init'),
+ CONFIG = require('../lib/config'),
handler = require('../lib/handler');
function usage() {
@@ -13,19 +14,34 @@ function serve(directory, port) {
directory = path.resolve(directory);
var handlerInstance = handler(directory);
- http.createServer(handlerInstance).listen(port || 0xD0C);
+
+ http.createServer(handlerInstance).listen(port || CONFIG['port']);
+}
+
+function showServerStartInfo(port) {
+
+ var now = (new Date()).toLocaleString(),
+ CONFIG_STARTTIPS = CONFIG['startTips'] + port,
+ CONFIG_DIVISION = CONFIG['division'];
+
+ console.log(CONFIG_DIVISION);
+ console.log(now);
+ console.log(CONFIG['copyright']);
+ console.log(CONFIG_STARTTIPS);
+ console.log(CONFIG_DIVISION);
}
var args = process.argv.slice(2),
command = (args[0] || '').toLowerCase(),
directory = args[1] || '.',
- port = Number(args[2]);
+ port = Number(args[2]) || CONFIG['port'];
switch (command) {
case 'init':
return init(directory);
case 'serve':
serve(directory, port);
+ showServerStartInfo(port);
return;
default:
return usage();
View
@@ -1,11 +1,26 @@
var path = require('path'),
CONFIG = {
- configDir: '.mdserver',
- localConfigDir: '../config'
-};
+ // config dir of the target dir
+ configDir: '.mdserver',
+ // local config dir
+ localConfigDir: '../config',
+ // default port
+ port: '7878',
+ host: 'localhost',
+ division: '*=====================================*',
+ copyright: '-- by zhiyelee <http://blog.tsnrose.com>',
+ };
+// style path
CONFIG['styleSheetPath'] = CONFIG['configDir'] + '/base.css';
+
+// template path
CONFIG['templatePath'] = CONFIG['configDir'] + '/template.html';
+
+// server start tips
+CONFIG['startTips'] = 'mdserver started, please visit: http://' + CONFIG['host'] + ':';
+
+// server init command
CONFIG['initCmd'] = 'cp -rf ' + path.resolve(__dirname, CONFIG['localConfigDir']) + '/* ';
module.exports = CONFIG;

0 comments on commit 64f602a

Please sign in to comment.