From c74f6111f61ecf36118d7207d06ed4072f5d56e1 Mon Sep 17 00:00:00 2001 From: Pierre Viara <pierre.viara@outlook.com> Date: Tue, 29 Aug 2023 16:07:57 +0200 Subject: [PATCH] tech(app): extract code to new classes --- README.md | 6 +++--- package.json | 2 +- src/app.ts | 7 ++----- src/infrastructure/express-application.ts | 9 +++++++++ src/infrastructure/express-server.ts | 13 +++++++++++++ 5 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/infrastructure/express-application.ts create mode 100644 src/infrastructure/express-server.ts diff --git a/README.md b/README.md index c505d20..983448d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # README -Ce repository a été conçu comme la base de ce que sera votre projet Express.js une fois votre setup terminé. Prenez soin de lire chaque étape et ne manquez pas de feuilleter les pages de documentation qui vous sont partagées. +Ce repository a été conçu comme la base de ce que sera votre projet Express.js une fois le cours terminé. Prenez soin de lire chaque étape et ne manquez pas de feuilleter les pages de documentation qui vous sont partagées. ## Environnement de développement 1. Télécharger puis installer **Node.js** (LTS, i.e. Long-Term Support) @@ -89,7 +89,7 @@ Ouvrez votre `package.json` et ajoutez une ligne à l'objet `scripts` : 1. Ouvrez votre `package.json` et ajoutez une ligne à l'objet `scripts` : ```json "scripts": { - "test": "jest", + "test": "jest --passWithNoTests", } ``` @@ -143,4 +143,4 @@ npm run dev # Exécute le script 'dev' de l'objet 'scripts' > Listening on port 3000 ``` -**Félicitations !** 🥳🎉 Vous avez développé votre serveur Express.js. +**Félicitations !** 🥳🎉 Vous avez créé votre application back-end ! diff --git a/package.json b/package.json index 48874d4..0b793c1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "npx ts-node-dev src/app.ts", "format": "prettier --write \"src/**/*.ts\"", - "test": "jest" + "test": "jest --passWithNoTests" }, "keywords": [], "author": "", diff --git a/src/app.ts b/src/app.ts index 6f7e7d8..4e386dc 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,3 @@ -import express from 'express'; +import { ExpressApplication } from './infrastructure/express-application'; -const app = express(); -const port = 3000; - -app.listen(port, () => console.log(`> Listening on port ${port}`)); +new ExpressApplication().bootstrap(); diff --git a/src/infrastructure/express-application.ts b/src/infrastructure/express-application.ts new file mode 100644 index 0000000..d7996f0 --- /dev/null +++ b/src/infrastructure/express-application.ts @@ -0,0 +1,9 @@ +import { ExpressServer } from './express-server'; + +export class ExpressApplication { + private server = new ExpressServer('3000'); + + bootstrap(): void { + this.server.bootstrap(); + } +} diff --git a/src/infrastructure/express-server.ts b/src/infrastructure/express-server.ts new file mode 100644 index 0000000..87561a1 --- /dev/null +++ b/src/infrastructure/express-server.ts @@ -0,0 +1,13 @@ +import express from 'express'; + +export class ExpressServer { + private express = express(); + + constructor(private port: string) {} + + bootstrap(): void { + this.express.listen(this.port, () => { + console.log(`> Listening on port ${this.port}`); + }); + } +} -- GitLab