From cae7d2da979b33312e9a6c4000a3d8fe58bc6c65 Mon Sep 17 00:00:00 2001
From: Ivan Alglave <ivanalglave@outlook.fr>
Date: Tue, 8 Nov 2022 11:08:24 +0100
Subject: [PATCH] added config support

---
 src/config/config.model.ts      | 7 +++++++
 src/config/config.template.json | 5 +++++
 src/config/index.ts             | 7 +++++++
 src/main.ts                     | 3 ++-
 tsconfig.json                   | 3 ++-
 5 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 src/config/config.model.ts
 create mode 100644 src/config/config.template.json
 create mode 100644 src/config/index.ts

diff --git a/src/config/config.model.ts b/src/config/config.model.ts
new file mode 100644
index 0000000..18c0cae
--- /dev/null
+++ b/src/config/config.model.ts
@@ -0,0 +1,7 @@
+export interface IServerConfig {
+  port: number;
+}
+
+export interface IConfig {
+  server: IServerConfig;
+}
diff --git a/src/config/config.template.json b/src/config/config.template.json
new file mode 100644
index 0000000..88fb611
--- /dev/null
+++ b/src/config/config.template.json
@@ -0,0 +1,5 @@
+{
+  "server": {
+    "port": 0
+  }
+}
diff --git a/src/config/index.ts b/src/config/index.ts
new file mode 100644
index 0000000..8baff1d
--- /dev/null
+++ b/src/config/index.ts
@@ -0,0 +1,7 @@
+import _config from './config.json';
+import { IConfig } from './config.model';
+
+const config = _config as IConfig;
+
+export const server = config.server;
+export default config;
diff --git a/src/main.ts b/src/main.ts
index 13cad38..a946614 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,8 +1,9 @@
 import { NestFactory } from '@nestjs/core';
 import { AppModule } from './app.module';
+import { server } from './config';
 
 async function bootstrap() {
   const app = await NestFactory.create(AppModule);
-  await app.listen(3000);
+  await app.listen(server.port);
 }
 bootstrap();
diff --git a/tsconfig.json b/tsconfig.json
index adb614c..7a64609 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -16,6 +16,7 @@
     "noImplicitAny": false,
     "strictBindCallApply": false,
     "forceConsistentCasingInFileNames": false,
-    "noFallthroughCasesInSwitch": false
+    "noFallthroughCasesInSwitch": false,
+    "resolveJsonModule": true
   }
 }
-- 
GitLab