Skip to content

Commit

Permalink
✨ Add version route
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jul 7, 2024
1 parent 89bf256 commit dbe4345
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -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: [],
})
Expand Down
12 changes: 12 additions & 0 deletions src/modules/misc/misc.module.ts
Original file line number Diff line number Diff line change
@@ -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{}
6 changes: 6 additions & 0 deletions src/modules/misc/models/responses/version.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {ApiProperty} from "@nestjs/swagger";

export class VersionResponse{
@ApiProperty()
version: string;
}
20 changes: 20 additions & 0 deletions src/modules/misc/version.controller.ts
Original file line number Diff line number Diff line change
@@ -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<string>("npm_package_version")};
}
}

0 comments on commit dbe4345

Please sign in to comment.