Skip to content

Commit 6bdd7d7

Browse files
committed
Host and port made configurable
1 parent b159817 commit 6bdd7d7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22

3+
"host": "localhost",
4+
"port": 7777,
5+
36
"keyLength": 6
47

58
}

lib/document_handler.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ var winston = require('winston');
33
// For handling serving stored documents
44

55
var DocumentHandler = function(options) {
6-
this.keyLength = options.keyLength || 20;
6+
if (options) {
7+
this.keyLength = options.keyLength || 20;
8+
}
79
};
810

911
// TODO implement with FS backend

server.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ var winston = require('winston');
77
var StaticHandler = require('./lib/static_handler');
88
var DocumentHandler = require('./lib/document_handler');
99

10-
// Load the configuration
10+
// Load the configuration and set some defaults
1111
var config = JSON.parse(fs.readFileSync('config.js', 'utf8'));
12+
config.port = config.port || 7777;
13+
config.host = config.host || 'localhost';
1214

1315
// Configure logging - TODO make configurable
1416
winston.remove(winston.transports.Console);
@@ -40,4 +42,6 @@ http.createServer(function(request, response) {
4042
handler = new StaticHandler('./static');
4143
handler.handle(incoming.pathname, response);
4244

43-
}).listen(7777);
45+
}).listen(config.port, config.host);
46+
47+
console.info('listening on ' + config.host + ':' + config.port);

0 commit comments

Comments
 (0)