This commit modifies the logging of memory and heap usage in the app.ts file. The redundant newline code `\n` at the end of the log message has been removed to enhance readability and neatness of the logs. Signed-off-by: Mathis <yidhra@tuta.io>
65 lines
1.3 KiB
TypeScript
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 !\n");
|
|
} catch (err) {
|
|
logger.error(err);
|
|
throw null;
|
|
}
|
|
|
|
try {
|
|
app.listen(process.env["APP_PORT"]);
|
|
logger.info(
|
|
`Server is running !\n >> Memory total: ${
|
|
process.memoryUsage().rss / 1_000_000
|
|
} Mio\n >> Memory heap usage: ${
|
|
process.memoryUsage().heapUsed / 1_000_000
|
|
} Mio\n`,
|
|
);
|
|
} catch (error) {
|
|
logger.error(`Server failed to start: ${error}`);
|
|
process.exit(1);
|
|
}
|