forked from jadonk/bonescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (34 loc) · 1.04 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var b = require('bonescript');
var util = require('util');
var fs = require('fs');
var configFile = '/etc/default/bonescript';
var server;
//read the configuration from configFile
fs.readFile(configFile, {
encoding: 'ascii'
}, function read(err, data) {
if (err) {
server = b.serverStart(); //start server with default settings
} else {
data = JSON.parse(data); //start server with saved config
server = b.serverStart(data.port, data.directory, {
data: data.passphrase,
hash: data.hash
});
}
onServerStart();
});
function onServerStart() {
server.on('server$listening', serverListening);
server.on('server$error', serverError);
server.on('server$connection', serverConnection);
}
function serverListening() {
if (debug) winston.debug('Server listening');
}
function serverError(error) {
if (debug) winston.debug('Server error: ' + JSON.stringify(error));
}
function serverConnection(connection) {
if (debug) winston.debug('Server connection: ' + connection);
}