From 4ff1aa852df71cb81ca0a9bc31f7de73c6dea1f7 Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 29 Apr 2024 09:54:04 +0200 Subject: [PATCH] feat(app): add handling for app port from environment variable This commit imports the `process` module from `node:process` and changes the app to listen on a port specified by an environment variable (APP_PORT). It also adds an error handler to stop the server and log the error message if the server fails to start. Signed-off-by: Mathis --- src/app.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index ebceb05..19c9b17 100644 --- a/src/app.ts +++ b/src/app.ts @@ -6,6 +6,7 @@ import helmet from "helmet"; import AuthRouter from "@routes/auth/authRouter"; import CatalogRouter from "@routes/catalog/catalogRouter"; import RentRouter from "@routes/rent/rentRouter"; +import * as process from "node:process"; const logger = new Logger({ name: "App" }); @@ -43,5 +44,10 @@ try { throw null; } -//app.listen(3333) -logger.info('Server is running !') \ No newline at end of file +try { + app.listen(process.env["APP_PORT"]) + logger.info('Server is running !') +} catch (error) { + logger.error(`Server failed to start: ${error}`); + process.exit(1); +} \ No newline at end of file