-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserver.js
52 lines (44 loc) · 1.39 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
var express = require("express");
var compression = require('compression');
var expressApp = express();
expressApp.use(compression());
var webServer = require('./server/webserver.js');
var config = require('config');
var chalk = require('chalk');
var rpc = require('./server/ethrpc.js');
var accounting = require('./server/accounting.js');
var logError = chalk.red;
var logWarning = chalk.yellow;
var logInfo = chalk.gray;
var logSuccess = chalk.green;
console.log(logInfo("starting server.."));
var bodyParser = require('body-parser');
expressApp.use(bodyParser.json()); // to support JSON-encoded bodies
expressApp.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
expressApp.use(bodyParser.text());
expressApp.use(bodyParser.raw());
rpc.init(false, function(){
webServer.init(expressApp,function(){
accounting.init(function(){
rpc.startBlockPooler();
});
});
});
process.stdin.resume();
function exitHandler(options, err) {
if (options.cleanup) {
console.log(logInfo('clean'));
}
if (err) {
console.log(logError(err.stack));
}
if (options.exit) {
console.log(logWarning('received exit by SIGINT'));
process.exit();
}
}
process.on('exit', exitHandler.bind(null,{cleanup:true}));
process.on('SIGINT', exitHandler.bind(null, {exit:true}));