This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
72 lines (62 loc) · 1.67 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var fs = require('fs');
var http = require('http');
var https = require('https');
var path = require('path');
var settings = require('./settings');
var server = require('./board/server');
var board = require('./board/board');
var parser = require('./board/parser');
var printer = require('./board/printer');
var collection = require('./board/collection');
printer.PrintOk('Starting ConBoard', 'nom');
printer.PrintOk('Setting up data');
if (Date.now() < settings.minTime) {
printer.PrintError('Server time too low!');
}
setupData(settings.dataPath + '/' + settings.sourceName, storeData);
// Server start
server.createServer(collection, {
port: settings.port,
staticPath: path.resolve(settings.wwwPath),
dataPath: path.resolve(settings.dataPath)
});
server.start();
function storeData(err, data) {
if (!err, !!data) {
printer.PrintOk('End of data setup');
collection.Init(
{
recordIndex: settings.recordIndex,
recordFields: settings.recordFields,
recordCatField: settings.recordCatField
},
data
);
}
else {
printer.PrintError('Error while loading source data');
gracefulExit();
}
}
function prettyPrint(err, data) {
if (!err, !!data) {
printer.PrintJson(data);
printer.PrintOk('End of data');
}
}
function setupData(sourcePath, callback) {
try {
var sourceData = fs.readFileSync(sourcePath);
}
catch(exception) {
sourceData = '';
printer.PrintError('And error ocured while reading the source file.');
printer.PrintError('Stack trace:\n' + exception.stack);
}
parser.Parse(sourceData, callback);
}
function gracefulExit() {
printer.PrintOk('Exiting ConBoard');
process.exit();
}
process.on('SIGINT', gracefulExit).on('SIGTERM', gracefulExit);