Mathis 1cbc771251
feat(app): update debug syntax, refactor HTTP status codes
- Updated import and usage of `isDebugMode` function across multiple controllers and services for better readability
- Improved the use of HTTP status codes in `auth.controller.ts` for more accurate responses
- Refactored HTTP status codes `HttpStatusCode` enum to include detailed comments

Signed-off-by: Mathis <yidhra@tuta.io>
2024-05-02 15:29:19 +02:00

65 lines
1.3 KiB
TypeScript

import * as process from "node:process";
import AuthRouter from "@routes/auth/authRouter";
import CatalogRouter from "@routes/catalog/catalogRouter";
import RentRouter from "@routes/rent/rentRouter";
import compression from "compression";
import cors from "cors";
import express, { type Express } from "express";
import helmet from "helmet";
import { Logger } from "tslog";
const logger = new Logger({
name: "App",
});
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 request body
app.use(express.json());
// parse urlencoded request body
app.use(
express.urlencoded({
extended: true,
}),
);
// gzip compression
app.use(compression());
try {
app.use("/auth", AuthRouter);
app.use("/catalog", CatalogRouter);
app.use("/rent", RentRouter);
logger.info("Routers loaded !");
} catch (err) {
logger.error(err);
throw null;
}
try {
app.listen(process.env["APP_PORT"]);
logger.info(
`Server is running !\n >> Memory total: ${Math.round(
process.memoryUsage().rss / 1_000_000,
)} Mio\n >> Memory heap: ${Math.round(
process.memoryUsage().heapUsed / 1_000_000,
)} Mio\n`,
);
} catch (error) {
logger.error(`Server failed to start: ${error}`);
process.exit(1);
}