2017-09-11 22:54:15 +08:00
|
|
|
const config = require("./config.js");
|
|
|
|
const Hook = require("./hook.js");
|
|
|
|
const IDMapping = require("./id_mapping.js");
|
|
|
|
const WebHooks = require("./web_hooks.js");
|
|
|
|
const WebServer = require("./web_server.js");
|
2017-09-12 03:16:11 +08:00
|
|
|
const redis = require("redis");
|
2017-09-15 01:09:02 +08:00
|
|
|
const UserMapping = require("./userMapping.js");
|
2017-11-07 02:43:05 +08:00
|
|
|
const async = require("async");
|
2017-09-11 22:54:15 +08:00
|
|
|
|
|
|
|
// Class that defines the application. Listens for events on redis and starts the
|
|
|
|
// process to perform the callback calls.
|
|
|
|
// TODO: add port (-p) and log level (-l) to the command line args
|
2017-08-25 00:22:30 +08:00
|
|
|
module.exports = class Application {
|
2017-09-11 22:54:15 +08:00
|
|
|
|
|
|
|
constructor() {
|
2018-07-26 09:05:51 +08:00
|
|
|
const options = {
|
2018-07-26 02:14:55 +08:00
|
|
|
host : process.env.REDIS_HOST || config.redis.host,
|
|
|
|
port : process.env.REDIS_PORT || config.redis.port
|
|
|
|
};
|
|
|
|
config.redis.pubSubClient = redis.createClient(options);
|
|
|
|
config.redis.client = redis.createClient(options);
|
2017-09-11 22:54:15 +08:00
|
|
|
this.webHooks = new WebHooks();
|
|
|
|
this.webServer = new WebServer();
|
|
|
|
}
|
|
|
|
|
2017-11-07 02:43:05 +08:00
|
|
|
start(callback) {
|
2017-09-11 22:54:15 +08:00
|
|
|
Hook.initialize(() => {
|
2017-09-15 01:09:02 +08:00
|
|
|
UserMapping.initialize(() => {
|
|
|
|
IDMapping.initialize(()=> {
|
2017-11-07 02:43:05 +08:00
|
|
|
async.parallel([
|
|
|
|
(callback) => { this.webServer.start(config.server.port, callback) },
|
|
|
|
(callback) => { this.webServer.createPermanents(callback) },
|
|
|
|
(callback) => { this.webHooks.start(callback) }
|
|
|
|
], (err,results) => {
|
|
|
|
if(err != null) {}
|
|
|
|
typeof callback === 'function' ? callback() : undefined;
|
|
|
|
});
|
2017-09-15 01:09:02 +08:00
|
|
|
});
|
2017-09-11 22:54:15 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-08-25 00:22:30 +08:00
|
|
|
};
|