This repository has been archived by the owner on Mar 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.js
51 lines (44 loc) · 1.37 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
global.__basedir = __dirname;
process.title = "miner-manager";
const express = require('express');
const bodyParser = require('body-parser');
const log4js = require('log4js');
const miningController = require('./api/controllers/miningController');
log4js.configure({
appenders: [
{ type: 'console' },
{ type: 'file', filename: 'data/system.log', maxLogSize: 50*1024, backups:1, category: ['system', 'config', 'mining', 'stratumTest'] }
]
});
const logger = log4js.getLogger('system');
const app = express();
app.use(bodyParser.urlencoded({
extended: true,
limit: '50mb'
}));
app.use(bodyParser.json({
limit: '50mb'
}));
app.use(express.static(__dirname + '/app'));
require(`${__basedir}/api/routes`)(app);
// wildcard route to get angular app loaded before angular takes over client-side routing
app.route('*').get((req, res) => {
res.sendFile('index.html', {
root: './'
});
});
global.listener = app.listen(process.env.PORT || 8082, () => {
logger.info(`server running on port ${listener.address().port}`);
});
process.on('uncaughtException', (err) => {
logger.error(err.stack);
});
// hook exit signals and stop mining
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
'SIGBUS', 'SIGFPE', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
].forEach((sig) => {
process.on(sig, async () => {
await miningController.stopAllMiner();
process.exit(0);
});
});