44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
|
import "dotenv/config"; // Load Envars
|
||
|
|
||
|
// Imports
|
||
|
import fig from "figlet";
|
||
|
import http from "http";
|
||
|
import { INFO, OK, logInfo } from "../util/logging.js";
|
||
|
// import "../utils/preload.js"; // Load Globals
|
||
|
|
||
|
// Import Core Modules
|
||
|
import applySockets from "../sockets/handler.js";
|
||
|
import JobManager from "./JobManager.js";
|
||
|
|
||
|
// 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];
|
||
|
this.jobs = new JobManager(options.maxClientJobs ?? 3);
|
||
|
this.port = options.port ?? port;
|
||
|
}
|
||
|
|
||
|
async _preinitialize() {
|
||
|
logInfo(fig.textSync(title, "Cosmike"));
|
||
|
INFO("INIT", "Initializing...");
|
||
|
this.app = (await import("./server.js")).default;
|
||
|
this.server = http.createServer(this.app);
|
||
|
this.sockets = applySockets(this.server, this.jobs);
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|