//import { Log } from "@ubccpsc310/project-support"; //"@ubccpsc310/project-support": "^4.0.0", import Server from "./rest/Server"; /** * Main app class that is run with the node command. Starts the server. */ export class App { private server: Server | null = null; public async initServer(port: number): Promise { //Log.info(`App::initServer( ${port} ) - start`); //console.log(`App::initServer( ${port} ) - start`); this.server = new Server(port); return this.server .start() .then(() => { //Log.info("App::initServer() - started"); //console.log("App::initServer() - started"); }) .catch((err: Error) => { //Log.error(`App::initServer() - ERROR: ${err.message}`); //console.error(`App::initServer() - ERROR: ${err.message}`); }); } public async stop(): Promise { if (this.server) { await this.server.stop(); } } } // This ends up starting the whole system and listens on a hardcoded port (4321) //Log.info("App - starting"); //console.log("App - starting"); const port = parseInt(process.env.PORT || "4321", 10); const app = new App(); (async (): Promise => { await app.initServer(port); })(); const shutdown: () => Promise = async () => { //console.log("Shutdown signal received. Closing server..."); try { await app.stop(); //console.log("Server shut down gracefully."); process.exit(0); } catch { //console.error("Error during shutdown:", err); process.exit(1); } }; process.on("SIGTERM", shutdown); process.on("SIGINT", shutdown);