diff --git a/package.json b/package.json index 909afea..7d9b204 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "@nestjs/passport": "^10.0.2", "@nestjs/platform-express": "^10.0.0", "@nestjs/swagger": "^7.1.13", + "@nestjs/terminus": "^10.2.3", "@types/buffer-to-stream": "^1.0.3", "@types/passport": "^1.0.16", "@types/passport-jwt": "^3.0.13", diff --git a/src/app.controller.ts b/src/app.controller.ts deleted file mode 100644 index 199fd83..0000000 --- a/src/app.controller.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Controller, Get } from '@nestjs/common'; -import { AppService } from './app.service'; -import { ApiExcludeController } from '@nestjs/swagger'; - -@Controller() -@ApiExcludeController() -export class AppController { - constructor(private readonly appService: AppService) {} - - @Get('/healthcheck') - healthCheck(): string { - return this.appService.getHealthCheck(); - } -} diff --git a/src/app.module.ts b/src/app.module.ts index a637488..c734030 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,6 +1,5 @@ import { Module } from '@nestjs/common'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; +import { HealthController } from './health.controller'; import { DumpModule } from './dumps/dump.module'; import { ReportModule } from './report/report.module'; import { MongooseModule } from '@nestjs/mongoose'; @@ -8,6 +7,7 @@ import { ConfigModule } from '@nestjs/config'; import { AdminModule } from './admin/admin.module'; import { AuthModule } from './auth/auth.module'; import { CloudinaryModule } from './cloudinary/cloudinary.module'; +import { TerminusModule } from '@nestjs/terminus'; import { CommonModule } from './common/common.module'; @Module({ @@ -20,8 +20,9 @@ import { CommonModule } from './common/common.module'; AuthModule, CloudinaryModule, CommonModule, + TerminusModule, ], - controllers: [AppController], - providers: [AppService], + controllers: [HealthController], + providers: [], }) export class AppModule {} diff --git a/src/app.service.ts b/src/app.service.ts deleted file mode 100644 index 7ce0efd..0000000 --- a/src/app.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService { - getHealthCheck(): string { - return 'Tvarkau LietuvÄ… API is running'; - } -} diff --git a/src/health.controller.ts b/src/health.controller.ts new file mode 100644 index 0000000..0e155b5 --- /dev/null +++ b/src/health.controller.ts @@ -0,0 +1,21 @@ +import { Controller, Get } from '@nestjs/common'; +import { ApiExcludeController } from '@nestjs/swagger'; +import { + HealthCheckResult, + HealthCheckService, + MongooseHealthIndicator, +} from '@nestjs/terminus'; + +@Controller() +@ApiExcludeController() +export class HealthController { + constructor( + private health: HealthCheckService, + private mongoose: MongooseHealthIndicator, + ) {} + + @Get('/healthcheck') + healthCheck(): Promise { + return this.health.check([async () => this.mongoose.pingCheck('mongoose')]); + } +} diff --git a/yarn.lock b/yarn.lock index 875a0b5..09849d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -838,6 +838,14 @@ path-to-regexp "3.2.0" swagger-ui-dist "5.9.0" +"@nestjs/terminus@^10.2.3": + version "10.2.3" + resolved "https://registry.yarnpkg.com/@nestjs/terminus/-/terminus-10.2.3.tgz#72c8a66d04df52aeaae807551245480fd7239a75" + integrity sha512-iX7gXtAooePcyQqFt57aDke5MzgdkBeYgF5YsFNNFwOiAFdIQEhfv3PR0G+HlH9F6D7nBCDZt9U87Pks/qHijg== + dependencies: + boxen "5.1.2" + check-disk-space "3.4.0" + "@nestjs/testing@^10.0.0": version "10.2.7" resolved "https://registry.yarnpkg.com/@nestjs/testing/-/testing-10.2.7.tgz#50408ccb4c809d216a12d60ac7932fd6ad7fedf4" @@ -1530,6 +1538,13 @@ ajv@^6.12.4, ajv@^6.12.5: json-schema-traverse "^0.4.1" uri-js "^4.2.2" +ansi-align@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59" + integrity sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w== + dependencies: + string-width "^4.1.0" + ansi-colors@4.1.3: version "4.1.3" resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b" @@ -1793,6 +1808,20 @@ body-parser@1.20.2: type-is "~1.6.18" unpipe "1.0.0" +boxen@5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/boxen/-/boxen-5.1.2.tgz#788cb686fc83c1f486dfa8a40c68fc2b831d2b50" + integrity sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ== + dependencies: + ansi-align "^3.0.0" + camelcase "^6.2.0" + chalk "^4.1.0" + cli-boxes "^2.2.1" + string-width "^4.2.2" + type-fest "^0.20.2" + widest-line "^3.1.0" + wrap-ansi "^7.0.0" + bplist-parser@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/bplist-parser/-/bplist-parser-0.2.0.tgz#43a9d183e5bf9d545200ceac3e712f79ebbe8d0e" @@ -1954,6 +1983,11 @@ chardet@^0.7.0: resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== +check-disk-space@3.4.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/check-disk-space/-/check-disk-space-3.4.0.tgz#eb8e69eee7a378fd12e35281b8123a8b4c4a8ff7" + integrity sha512-drVkSqfwA+TvuEhFipiR1OC9boEGZL5RrWvVsOthdcvQNXyCCuKkEiTOTXZ7qxSf/GLwq4GvzfrQD/Wz325hgw== + chokidar@3.5.3, chokidar@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" @@ -2003,6 +2037,11 @@ class-validator@^0.14.0: libphonenumber-js "^1.10.14" validator "^13.7.0" +cli-boxes@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f" + integrity sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw== + cli-cursor@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307" @@ -5319,7 +5358,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -5875,6 +5914,13 @@ wide-align@^1.1.2: dependencies: string-width "^1.0.2 || 2 || 3 || 4" +widest-line@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-3.1.0.tgz#8292333bbf66cb45ff0de1603b136b7ae1496eca" + integrity sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg== + dependencies: + string-width "^4.0.0" + windows-release@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/windows-release/-/windows-release-4.0.0.tgz#4725ec70217d1bf6e02c7772413b29cdde9ec377"