This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
96 lines (83 loc) · 2.98 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
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
94
95
96
/**
* Copyright (C) 2015 Austin Peterson
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* This is the main entry point for AKP48. This module handles hot-reloading so that everything can be hot-reloaded.
*/
var fs = require('fs');
var path = require('path');
var bunyan = require('bunyan');
var validator = require('validator');
var config = require('./data/config/global');
var InstanceManager = require('./InstanceManager');
var GitProcessor = require('./GitProcessor');
var i18n = new (require('./i18n'))(config.locale || "en-us");
GLOBAL.i18n = i18n;
if(!config.productionMode) {
require('longjohn');
}
var streams = [{
stream: process.stdout,
level: (config.log.level || 'info')
}];
if(config.log && config.log.logToFile) {
streams.push({
type: 'rotating-file',
level: (config.log.level || 'info'),
path: path.resolve("./log/AKP48.log"),
period: '1d',
count: 7
});
}
var log = bunyan.createLogger({
name: 'AKP48',
module: 'Server',
lang: (config.locale || "en-us"),
streams: streams,
serializers: {
err: bunyan.stdSerializers.err
}
});
require('./polyfill.js')(log);
//Initialize an InstanceManager.
var instanceManager = new InstanceManager(log);
//Initialize a GitProcessor.
var gitProcessor = new GitProcessor(log, instanceManager);
//create instances using the currently existing configuration folders.
//TODO: If none exist, use default settings.
fs.readdir(path.resolve("data/config"), function(err, files) {
//check for error, quit now if we have any.
if(err) {log.fatal(err); return;}
//loop through files in the config folder.
files.forEach(function(file) {
//stat each file
fs.stat(path.resolve("data/config", file), function(err, stat){
//if error, return
if(err) {log.fatal(err); return;}
//if the 'file' is actually a directory, and the name is a valid UUID,
//start an AKP48 instance using it.
if(stat.isDirectory() && validator.isUUID(file) && file !== "00000000-0e6c-41f4-a322-29bd4d336ecc") {
instanceManager.startInstance(file, path.resolve("data/config", file), log);
}
});
});
});
//todo: better exception handling plz
if(config.productionMode) {
process.on('uncaughtException', function(err) {
log.fatal({err: err}, i18n.getString("caughtException"), err);
});
}