forked from n42k/brikkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (35 loc) · 1.14 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
require('dotenv').config({
path: 'brikkit.conf'
});
const fs = require('fs');
const { execSync } = require('child_process');
execSync(`mkdir -p logs`);
execSync(`mkdir -p conf`);
execSync(`mkdir -p saved`);
execSync(`mkdir -p plugins`);
const iso8601DateString = (new Date()).toISOString();
// remove colons from the date string; required for windows
const colonlessDateString = iso8601DateString.split(':').join('');
const logFile = `logs/log_${colonlessDateString}.txt`;
let stream = fs.createWriteStream(logFile, {flags:'a'});
const oldConsoleLog = console.log;
console.log = (...msg) => {
oldConsoleLog(...msg);
if(process.env.LOG === 'FALSE')
return;
stream.write(msg.join(' ') + '\n');
}
stream.on('error', err => {throw err});
stream.on('open', fd => {
const Brikkit = new (require('./brikkit.js'))({}, stream);
Brikkit.getPluginSystem().loadAllPlugins();
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
process.on('uncaughtException', err => {
console.log(' --- SERVER END --- ');
console.log(err.stack);
fs.appendFileSync(logFile, err.stack);
process.exit();
});