Refactor out server init to index.js
This commit is contained in:
parent
128367bfc4
commit
542461a533
27
index.js
Normal file
27
index.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
Copyright (c) 2013 Calvin Montgomery
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Server = require("./lib/server");
|
||||||
|
var Config = require("./lib/config");
|
||||||
|
|
||||||
|
Config.load("cfg.json", function (cfg) {
|
||||||
|
var sv = Server.init(cfg);
|
||||||
|
if(!cfg["debug"]) {
|
||||||
|
process.on("uncaughtException", function (err) {
|
||||||
|
Logger.errlog.log("[SEVERE] Uncaught Exception: " + err);
|
||||||
|
Logger.errlog.log(err.stack);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("SIGINT", function () {
|
||||||
|
sv.shutdown();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
|
@ -62,7 +62,7 @@ function save(cfg, file) {
|
||||||
fs.writeFileSync(file, JSON.stringify(x, null, 4));
|
fs.writeFileSync(file, JSON.stringify(x, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.load = function (Server, file, callback) {
|
exports.load = function (file, callback) {
|
||||||
var cfg = {};
|
var cfg = {};
|
||||||
for(var k in defaults)
|
for(var k in defaults)
|
||||||
cfg[k] = defaults[k];
|
cfg[k] = defaults[k];
|
||||||
|
@ -102,7 +102,6 @@ exports.load = function (Server, file, callback) {
|
||||||
cfg["loaded"] = true;
|
cfg["loaded"] = true;
|
||||||
|
|
||||||
save(cfg, file);
|
save(cfg, file);
|
||||||
Server.cfg = cfg;
|
callback(cfg);
|
||||||
callback();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
Copyright (c) 2013 Calvin Montgomery
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
|
@ -276,6 +287,16 @@ var singleton = null;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: function (cfg) {
|
init: function (cfg) {
|
||||||
|
Logger.syslog.log("Starting CyTube v" + VERSION);
|
||||||
|
var chanlogpath = path.join(__dirname, "../chanlogs");
|
||||||
|
fs.exists(chanlogpath, function (exists) {
|
||||||
|
exists || fs.mkdir(chanlogpath);
|
||||||
|
});
|
||||||
|
|
||||||
|
var chandumppath = path.join(__dirname, "../chandump");
|
||||||
|
fs.exists(chandumppath, function (exists) {
|
||||||
|
exists || fs.mkdir(chandumppath);
|
||||||
|
});
|
||||||
singleton = new Server(cfg);
|
singleton = new Server(cfg);
|
||||||
return singleton;
|
return singleton;
|
||||||
},
|
},
|
||||||
|
@ -284,29 +305,3 @@ module.exports = {
|
||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.syslog.log("Starting CyTube v" + VERSION);
|
|
||||||
var chanlogpath = path.join(__dirname, "../chanlogs");
|
|
||||||
fs.exists(chanlogpath, function (exists) {
|
|
||||||
exists || fs.mkdir(chanlogpath);
|
|
||||||
});
|
|
||||||
|
|
||||||
var chandumppath = path.join(__dirname, "../chandump");
|
|
||||||
fs.exists(chandumppath, function (exists) {
|
|
||||||
exists || fs.mkdir(chandumppath);
|
|
||||||
});
|
|
||||||
|
|
||||||
var x = {};
|
|
||||||
Config.load(x, path.join(__dirname, "../cfg.json"), function () {
|
|
||||||
module.exports.init(x.cfg);
|
|
||||||
if(!singleton.cfg["debug"]) {
|
|
||||||
process.on("uncaughtException", function (err) {
|
|
||||||
Logger.errlog.log("[SEVERE] Uncaught Exception: " + err);
|
|
||||||
Logger.errlog.log(err.stack);
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on("SIGINT", function () {
|
|
||||||
singleton.shutdown();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue