Skip to content

Commit 950d107

Browse files
committed
feat: add healthcheck
1 parent 67495f5 commit 950d107

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

package-lock.json

+48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@nestjs/passport": "^7.1.5",
4141
"@nestjs/platform-express": "7.6.17",
4242
"@nestjs/swagger": "^4.8.0",
43+
"@nestjs/terminus": "^7.2.0",
4344
"@nestjs/typeorm": "^7.1.5",
4445
"argon2": "^0.27.2",
4546
"bull": "^3.22.6",

src/app.module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BullModule } from '@nestjs/bull';
22
import { Module } from '@nestjs/common';
33
import { ConfigModule } from '@nestjs/config';
4+
import { TerminusModule } from '@nestjs/terminus';
45
import { TypeOrmModule } from '@nestjs/typeorm';
56
import { RedisModule } from 'nestjs-redis';
67
import { AppController } from './app.controller';
@@ -9,6 +10,7 @@ import ormconfig from './ormconfig';
910
import redisconfig from './redisconfig';
1011
import { SubmissionsModule } from './submissions/submissions.module';
1112
import { UsersModule } from './users/users.module';
13+
import { HealthController } from './health/health.controller';
1214

1315
@Module({
1416
imports: [
@@ -21,8 +23,9 @@ import { UsersModule } from './users/users.module';
2123
redis: redisconfig,
2224
}),
2325
RedisModule.register(redisconfig),
26+
TerminusModule,
2427
],
25-
controllers: [AppController],
28+
controllers: [AppController, HealthController],
2629
providers: [],
2730
})
2831
export class AppModule {}

src/health/health.controller.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Controller, Get } from '@nestjs/common';
2+
import {
3+
HealthCheck,
4+
HealthCheckResult,
5+
HealthCheckService,
6+
HealthIndicatorResult,
7+
TypeOrmHealthIndicator,
8+
} from '@nestjs/terminus';
9+
import { RedisService } from 'nestjs-redis';
10+
11+
@Controller('health')
12+
export class HealthController {
13+
constructor(
14+
private health: HealthCheckService,
15+
private db: TypeOrmHealthIndicator,
16+
private redis: RedisService,
17+
) {}
18+
19+
@Get()
20+
@HealthCheck()
21+
check(): Promise<HealthCheckResult> {
22+
return this.health.check([
23+
(): Promise<HealthIndicatorResult> => this.db.pingCheck('database'),
24+
]);
25+
}
26+
}

0 commit comments

Comments
 (0)