import * as process from "node:process"; import { EnvUtils } from "@utils/env.util"; import { LogsUtils } from "@utils/logs.util"; import compression from "compression"; import cors from "cors"; import express, { type Express } from "express"; import helmet from "helmet"; import AuthRouter from "@routers/auth.router"; console.log("\n\n> Starting...\n\n\n\n"); const logger = new LogsUtils("OnlyDevs"); const envs = new EnvUtils("OnlyDevs"); const app: Express = express(); // enable cors app.use(cors()); app.options("*", cors()); // enable xss sanitizer app.use( helmet({ xXssProtection: true, }), ); app.use(helmet.xXssProtection()); // parse json requests body app.use(express.json()); // parse urlencoded requests body app.use( express.urlencoded({ extended: true, }), ); // gzip compression app.use(compression()); try { app.use("/auth", AuthRouter); logger.info("Routers loaded !"); } catch (err) { logger.error(err); throw null; } try { const port = envs.get("APP_PORT") || "3000"; app.listen(Number.parseInt(port)); logger.info( `Server is running ! (port:${port})`, `Memory total: ${Math.round( process.memoryUsage().rss / 1_000_000, )} Mio\n - Memory used by V8: ${Math.round( process.memoryUsage().heapUsed / 1_000_000, )} Mio`, ); } catch (error) { logger.error(`Server failed to start: ${error}`); process.exit(1); }