From 94b2ce2d167e38b024716e933370fb646b18a215 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 3 May 2024 17:08:01 +0200 Subject: [PATCH] move app source --- Express/barAndCafe/src/app.ts | 21 +++++++++++++++++++ .../barAndCafe/{index.ts => src/server.ts} | 8 +------ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 Express/barAndCafe/src/app.ts rename Express/barAndCafe/{index.ts => src/server.ts} (61%) diff --git a/Express/barAndCafe/src/app.ts b/Express/barAndCafe/src/app.ts new file mode 100644 index 0000000..943d8a9 --- /dev/null +++ b/Express/barAndCafe/src/app.ts @@ -0,0 +1,21 @@ +import express from "express"; + +/** + * Initialize Express application instance. + * @returns An initialized Express application object. + */ +const app = express(); + +/** + * Handle GET request for homepage route ('/'). + * Send back a simple text response. + * @param {express.Request} req - HTTP Request object. + * @param {express.Response} res - HTTP Response object. + */ +function getRoot(req: express.Request, res: express.Response) { + res.send("hello world from dev"); +} + +app.get("/", getRoot); + +export default app; \ No newline at end of file diff --git a/Express/barAndCafe/index.ts b/Express/barAndCafe/src/server.ts similarity index 61% rename from Express/barAndCafe/index.ts rename to Express/barAndCafe/src/server.ts index 7d6d177..625a94c 100644 --- a/Express/barAndCafe/index.ts +++ b/Express/barAndCafe/src/server.ts @@ -1,16 +1,10 @@ -import express from "express"; import * as dotenv from "dotenv"; +import app from "./app"; dotenv.config({path: '../../.env'}) const port = parseInt(process.env.BAR_PORT || '3000') -const app = express(); - -app.get("/", (req, res) => { - res.send("helloworld form dev") -}) - app.listen(port, () =>{ console.log(`serveur running in ${port}`) }) \ No newline at end of file