diff --git a/package.json b/package.json index ac7cd56..a816f34 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "dependencies": { "@fastify/static": "^7.0.4", "@nestjs/common": "^10.0.0", + "@nestjs/config": "^3.2.3", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", "@nestjs/platform-fastify": "^10.3.9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5a66959..f5d8534 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@nestjs/common': specifier: ^10.0.0 version: 10.3.9(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/config': + specifier: ^3.2.3 + version: 3.2.3(@nestjs/common@10.3.9(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(rxjs@7.8.1) '@nestjs/core': specifier: ^10.0.0 version: 10.3.9(@nestjs/common@10.3.9(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.3.9)(reflect-metadata@0.2.2)(rxjs@7.8.1) @@ -507,6 +510,12 @@ packages: class-validator: optional: true + '@nestjs/config@3.2.3': + resolution: {integrity: sha512-p6yv/CvoBewJ72mBq4NXgOAi2rSQNWx3a+IMJLVKS2uiwFCOQQuiIatGwq6MRjXV3Jr+B41iUO8FIf4xBrZ4/w==} + peerDependencies: + '@nestjs/common': ^8.0.0 || ^9.0.0 || ^10.0.0 + rxjs: ^7.1.0 + '@nestjs/core@10.3.9': resolution: {integrity: sha512-NzZUfWAmaf8sqhhwoRA+CuqxQe+P4Rz8PZp5U7CdCbjyeB9ZVGcBkihcJC9wMdtiOWHRndB2J8zRfs5w06jK3w==} peerDependencies: @@ -1311,6 +1320,10 @@ packages: resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==} engines: {node: '>=6.0.0'} + dotenv-expand@10.0.0: + resolution: {integrity: sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==} + engines: {node: '>=12'} + dotenv@16.4.5: resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} engines: {node: '>=12'} @@ -3618,6 +3631,14 @@ snapshots: class-transformer: 0.5.1 class-validator: 0.14.1 + '@nestjs/config@3.2.3(@nestjs/common@10.3.9(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(rxjs@7.8.1)': + dependencies: + '@nestjs/common': 10.3.9(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + dotenv: 16.4.5 + dotenv-expand: 10.0.0 + lodash: 4.17.21 + rxjs: 7.8.1 + '@nestjs/core@10.3.9(@nestjs/common@10.3.9(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.3.9)(reflect-metadata@0.2.2)(rxjs@7.8.1)': dependencies: '@nestjs/common': 10.3.9(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) @@ -4512,6 +4533,8 @@ snapshots: dependencies: esutils: 2.0.3 + dotenv-expand@10.0.0: {} + dotenv@16.4.5: {} eastasianwidth@0.2.0: {} diff --git a/src/app.module.ts b/src/app.module.ts index be27a61..9d1b3a9 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,7 +1,12 @@ import {Module} from "@nestjs/common"; +import {ConfigModule} from "@nestjs/config"; +import {MiscModule} from "./modules/misc/misc.module"; @Module({ - imports: [], + imports: [ + ConfigModule.forRoot({isGlobal: true}), + MiscModule, + ], controllers: [], providers: [], }) diff --git a/src/modules/misc/misc.module.ts b/src/modules/misc/misc.module.ts new file mode 100644 index 0000000..e3f6474 --- /dev/null +++ b/src/modules/misc/misc.module.ts @@ -0,0 +1,12 @@ +import {Module} from "@nestjs/common"; +import {ConfigModule} from "@nestjs/config"; +import {VersionController} from "./version.controller"; + +@Module({ + imports: [ + ConfigModule.forRoot({isGlobal: true}), + ], + controllers: [VersionController], + providers: [], +}) +export class MiscModule{} diff --git a/src/modules/misc/models/responses/version.response.ts b/src/modules/misc/models/responses/version.response.ts new file mode 100644 index 0000000..8332787 --- /dev/null +++ b/src/modules/misc/models/responses/version.response.ts @@ -0,0 +1,6 @@ +import {ApiProperty} from "@nestjs/swagger"; + +export class VersionResponse{ + @ApiProperty() + version: string; +} diff --git a/src/modules/misc/version.controller.ts b/src/modules/misc/version.controller.ts new file mode 100644 index 0000000..f84397c --- /dev/null +++ b/src/modules/misc/version.controller.ts @@ -0,0 +1,20 @@ +import {Controller, Get, HttpStatus} from "@nestjs/common"; +import {ApiResponse, ApiTags} from "@nestjs/swagger"; +import {VersionResponse} from "./models/responses/version.response"; +import {ConfigService} from "@nestjs/config"; + + +@Controller("version") +@ApiTags("Version") +export class VersionController{ + + constructor( + private readonly configService: ConfigService, + ){} + + @Get() + @ApiResponse({status: HttpStatus.OK, description: "Returns the version of the application", type: VersionResponse}) + getVersion(): VersionResponse{ + return {version: this.configService.get("npm_package_version")}; + } +}