2022-05-05 12:35:47 +00:00
|
|
|
// Imports
|
|
|
|
import fig from "figlet";
|
|
|
|
import http from "http";
|
2022-07-12 21:26:36 +00:00
|
|
|
import express from "express";
|
2022-05-05 12:35:47 +00:00
|
|
|
import { INFO, OK, logInfo } from "../util/logging.js";
|
|
|
|
|
|
|
|
// Import Core Modules
|
2022-07-12 21:26:36 +00:00
|
|
|
import buildRoutes from "../routes/router.js";
|
|
|
|
import buildPostgres from "../database/postgres.js";
|
|
|
|
import injectSockets from "../sockets/socket-server.js";
|
|
|
|
import JobManager from "../jobs/JobManager.js";
|
|
|
|
import buildRabbiteer from "../rabbit/rabbit-workers.js";
|
2022-05-05 12:35:47 +00:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
const title = "QLTR";
|
|
|
|
const port = process.env.QUALITEER_DEV_PORT ?? 52000;
|
|
|
|
|
|
|
|
// Class
|
|
|
|
export default class Qualiteer {
|
|
|
|
constructor(options = {}) {
|
|
|
|
for (var k in options) this[k] = options[k];
|
2022-07-12 21:26:36 +00:00
|
|
|
this.jobs = JobManager;
|
2022-05-05 12:35:47 +00:00
|
|
|
this.port = options.port ?? port;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _preinitialize() {
|
2022-05-08 01:36:22 +00:00
|
|
|
logInfo(fig.textSync(title, "Cyberlarge"));
|
2022-05-05 12:35:47 +00:00
|
|
|
INFO("INIT", "Initializing...");
|
2022-07-12 21:26:36 +00:00
|
|
|
this.app = express();
|
|
|
|
this.pg = buildPostgres();
|
2022-05-05 12:35:47 +00:00
|
|
|
this.server = http.createServer(this.app);
|
2022-07-12 21:26:36 +00:00
|
|
|
this.sockets = injectSockets(this.server, this.jobs);
|
|
|
|
this.routes = buildRoutes(this.pg, this.sockets);
|
|
|
|
this.rabbiteer = buildRabbiteer(this.pg, this.sockets);
|
|
|
|
this.app.use(this.routes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async _connect() {
|
|
|
|
await this.pg.connect();
|
|
|
|
// await this.rabbiteer.connect();
|
2022-05-05 12:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
const qt = this;
|
|
|
|
return new Promise(async function init(res) {
|
2022-07-12 21:26:36 +00:00
|
|
|
qt._preinitialize();
|
|
|
|
await qt._connect();
|
2022-05-05 12:35:47 +00:00
|
|
|
qt.server.listen(qt.port, function onStart() {
|
|
|
|
OK("SERVER", `Running on ${qt.port}`);
|
|
|
|
res();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|