[TS] Renamed file extensions to typescript
This commit is contained in:
parent
4d5b347767
commit
4a6f20fa7b
31 changed files with 12 additions and 0 deletions
51
lib/Minecluster.ts
Normal file
51
lib/Minecluster.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
// 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 "./server/router.js";
|
||||
import injectSockets from "./server/sockets.js";
|
||||
import pg from "./database/postgres.js";
|
||||
|
||||
// Constants
|
||||
const title = "MCL";
|
||||
const port = process.env.MCL_DEV_PORT ?? 52000;
|
||||
|
||||
// Class
|
||||
export default class Minecluster {
|
||||
constructor(options = {}) {
|
||||
for (var k in options) this[k] = options[k];
|
||||
this.port = options.port ?? port;
|
||||
}
|
||||
|
||||
async _preinitialize() {
|
||||
logInfo(fig.textSync(title, "Larry 3D"));
|
||||
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.sockets);
|
||||
this.app.use(this.routes);
|
||||
OK("INIT", "Initialized!");
|
||||
}
|
||||
|
||||
async _connect() {
|
||||
await this.pg.connect();
|
||||
}
|
||||
|
||||
start() {
|
||||
const mcl = this;
|
||||
|
||||
return new Promise(async function init(res) {
|
||||
mcl._preinitialize();
|
||||
await mcl._connect();
|
||||
mcl.server.listen(mcl.port, function onStart() {
|
||||
OK("SERVER", `Running on ${mcl.port}`);
|
||||
res();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue