Minor Adjustments
This commit is contained in:
parent
1084f5d937
commit
f486d50efa
60 changed files with 1965 additions and 127 deletions
56
libold/server/core/Qualiteer.js
Normal file
56
libold/server/core/Qualiteer.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Imports
|
||||
import fig from "figlet";
|
||||
import http from "http";
|
||||
import express from "express";
|
||||
import { INFO, OK, logInfo } from "../util/logging.js";
|
||||
|
||||
// Import Core Modules
|
||||
import buildRoutes from "../routes/router.js";
|
||||
import pg from "../database/postgres.js";
|
||||
import injectSockets from "./socket-server.js";
|
||||
import JobManager from "./JobManager.js";
|
||||
import buildRabbiteer from "../rabbit/rabbit-workers.js";
|
||||
|
||||
// Constants
|
||||
const title = "QLTR";
|
||||
const rabbiteerEnabled = process.env.QUALITEER_RABBITEER_ENABLED !== "false";
|
||||
const port = process.env.QUALITEER_DEV_PORT ?? 52000;
|
||||
|
||||
// Class
|
||||
export default class Qualiteer {
|
||||
constructor(options = {}) {
|
||||
for (var k in options) this[k] = options[k];
|
||||
this.jobs = JobManager;
|
||||
this.port = options.port ?? port;
|
||||
}
|
||||
|
||||
async _preinitialize() {
|
||||
logInfo(fig.textSync(title, "Cyberlarge"));
|
||||
INFO("INIT", "Initializing...");
|
||||
this.app = express();
|
||||
this.pg = pg;
|
||||
this.server = http.createServer(this.app);
|
||||
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();
|
||||
if (!rabbiteerEnabled) return;
|
||||
await this.rabbiteer.connect();
|
||||
}
|
||||
|
||||
start() {
|
||||
const qt = this;
|
||||
return new Promise(async function init(res) {
|
||||
qt._preinitialize();
|
||||
await qt._connect();
|
||||
qt.server.listen(qt.port, function onStart() {
|
||||
OK("SERVER", `Running on ${qt.port}`);
|
||||
res();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue