Host and port made configurable

This commit is contained in:
John Crepezzi 2011-11-18 16:57:23 -05:00
parent b159817a27
commit 6bdd7d7fc5
3 changed files with 12 additions and 3 deletions

View file

@ -1,5 +1,8 @@
{ {
"host": "localhost",
"port": 7777,
"keyLength": 6 "keyLength": 6
} }

View file

@ -3,7 +3,9 @@ var winston = require('winston');
// For handling serving stored documents // For handling serving stored documents
var DocumentHandler = function(options) { var DocumentHandler = function(options) {
if (options) {
this.keyLength = options.keyLength || 20; this.keyLength = options.keyLength || 20;
}
}; };
// TODO implement with FS backend // TODO implement with FS backend

View file

@ -7,8 +7,10 @@ var winston = require('winston');
var StaticHandler = require('./lib/static_handler'); var StaticHandler = require('./lib/static_handler');
var DocumentHandler = require('./lib/document_handler'); var DocumentHandler = require('./lib/document_handler');
// Load the configuration // Load the configuration and set some defaults
var config = JSON.parse(fs.readFileSync('config.js', 'utf8')); var config = JSON.parse(fs.readFileSync('config.js', 'utf8'));
config.port = config.port || 7777;
config.host = config.host || 'localhost';
// Configure logging - TODO make configurable // Configure logging - TODO make configurable
winston.remove(winston.transports.Console); winston.remove(winston.transports.Console);
@ -40,4 +42,6 @@ http.createServer(function(request, response) {
handler = new StaticHandler('./static'); handler = new StaticHandler('./static');
handler.handle(incoming.pathname, response); handler.handle(incoming.pathname, response);
}).listen(7777); }).listen(config.port, config.host);
console.info('listening on ' + config.host + ':' + config.port);