-
Notifications
You must be signed in to change notification settings - Fork 4
/
inodeapi.js
93 lines (76 loc) · 2.15 KB
/
inodeapi.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Node Trinity source code
* See LICENCE file at the top of the source tree
*
* ******************************************
*
* inodeapi.js
* Launcher for Nodeapi module
*
* ******************************************
*
* Authors: K. Zhidanov, A. Prudanov, M. Vasil'ev
*/
const argv = require('yargs').argv;
const fs = require('fs');
const DB = require('./DB').DB;
const NodeAPI = require('./Nodeapi').NodeAPI;
const CONFIG_FILENAME = 'config.json';
let config = {
dbhost : 'localhost',
dbname : 'trinity',
dbuser : 'root',
dbpass : '',
loglevel : 'silly'
};
console.trace = function (...msg) {
console.log(...msg);
};
console.debug = function (...msg) {
console.log(...msg);
};
console.silly = function (...msg) {
console.log(...msg);
};
console.fatal = function (...msg) {
console.log(...msg);
process.exit(1);
};
console.info("Application started");
let config_filename = argv.config || CONFIG_FILENAME;
console.info('Loading config from', config_filename, '...');
let cfg = {};
try {
cfg = JSON.parse(fs.readFileSync(config_filename, 'utf8'));
config = Object.assign(config, cfg);
} catch (e) {
console.info('No configuration file found.')
}
config = Object.assign(config, argv);
console.info(`config = ${JSON.stringify(config)}`);
require('console-stamp')(console, {datePrefix: '[', pattern:'yyyy.mm.dd HH:MM:ss', level: config.loglevel, extend:{fatal:0, debug:4, trace:5, silly:6}, include:['silly', 'trace','debug','info','warn','error','fatal']});
let db = new DB({
host: config.dbhost,
port: config.dbport,
user: config.dbuser,
database: config.dbname,
password: config.dbpass.toString(),
dateStrings: true,
multipleStatements: true
},config);
BigInt.prototype.toJSON = function() { return this.toString() }
let start_nodeapi = function(config, db) {
console.info(`Starting nodeAPI`);
let api = new NodeAPI(config, db);
};
/*
let starter = async function(config, db, callback) {
if(!db.isConnected){
setTimeout(starter, 1000, config, db, callback);
return;
}
callback(config, db);
};
starter(config, db, start_nodeapi);
*/
start_nodeapi(config, db);