Skip to content

Commit 21b7e40

Browse files
committed
feat: 헬스 체크 API에 환경 변수 설정 추가
1 parent 08cf674 commit 21b7e40

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

backend/package-lock.json

Lines changed: 43 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dependencies": {
2323
"@nestjs/axios": "^4.0.1",
2424
"@nestjs/common": "^11.0.1",
25+
"@nestjs/config": "^4.0.2",
2526
"@nestjs/core": "^11.0.1",
2627
"@nestjs/platform-express": "^11.0.1",
2728
"@nestjs/terminus": "^11.0.0",

backend/src/app.module.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import { AppService } from './app.service';
44
import { HealthController } from './health/health.controller';
55
import { TerminusModule } from '@nestjs/terminus';
66
import { HttpModule } from '@nestjs/axios';
7+
import { ConfigModule } from '@nestjs/config';
78

89
@Module({
9-
imports: [TerminusModule, HttpModule],
10+
imports: [
11+
TerminusModule,
12+
HttpModule,
13+
ConfigModule.forRoot({
14+
isGlobal: true,
15+
}),
16+
],
1017
controllers: [AppController, HealthController],
1118
providers: [AppService],
1219
})
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Controller, Get } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
23
import {
34
HealthCheck,
45
HealthCheckService,
@@ -7,16 +8,29 @@ import {
78

89
@Controller('health')
910
export class HealthController {
11+
private readonly healthCheckName: string;
12+
private readonly healthCheckUrl: string;
13+
1014
constructor(
1115
private health: HealthCheckService,
1216
private http: HttpHealthIndicator,
13-
) {}
17+
private configService: ConfigService,
18+
) {
19+
this.healthCheckName = this.configService.get<string>(
20+
'HEALTH_CHECK_NAME',
21+
'Local_Health_Check',
22+
);
23+
this.healthCheckUrl = this.configService.get<string>(
24+
'HEALTH_CHECK_URL',
25+
'http://localhost:3000/ping',
26+
);
27+
}
1428

1529
@Get()
1630
@HealthCheck()
1731
check() {
1832
return this.health.check([
19-
() => this.http.pingCheck('server-check', 'http://localhost:3000/ping'),
33+
() => this.http.pingCheck(this.healthCheckName, this.healthCheckUrl),
2034
]);
2135
}
2236
}

0 commit comments

Comments
 (0)