qualiteer/lib/core/Qualiteer.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-05-05 12:35:47 +00:00
// Imports
import fig from "figlet";
import http from "http";
import { INFO, OK, logInfo } from "../util/logging.js";
// Import Core Modules
2022-05-05 20:30:24 +00:00
import expressApp from "./server.js";
2022-05-05 12:35:47 +00:00
import applySockets from "../sockets/handler.js";
2022-05-08 01:36:22 +00:00
import jobManager from "./JobManager.js";
2022-05-05 20:30:24 +00:00
import rabbiteer 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-05-08 01:36:22 +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-05-05 20:30:24 +00:00
this.app = expressApp;
2022-05-05 12:35:47 +00:00
this.server = http.createServer(this.app);
this.sockets = applySockets(this.server, this.jobs);
2022-05-05 20:30:24 +00:00
this.rabbiteer = rabbiteer;
2022-05-05 12:35:47 +00:00
}
start() {
const qt = this;
return new Promise(async function init(res) {
await qt._preinitialize();
qt.server.listen(qt.port, function onStart() {
OK("SERVER", `Running on ${qt.port}`);
res();
});
});
}
}