Listory/src/health-check/health-check.controller.ts

38 lines
948 B
TypeScript
Raw Normal View History

2020-05-03 04:32:14 +02:00
import { Controller, Get } from "@nestjs/common";
2021-05-25 18:12:42 +02:00
import { ConfigService } from "@nestjs/config";
2020-05-03 04:32:14 +02:00
import {
HttpHealthIndicator,
2020-05-03 04:32:14 +02:00
HealthCheck,
2021-05-25 18:12:42 +02:00
HealthCheckResult,
2020-05-03 04:32:14 +02:00
HealthCheckService,
TypeOrmHealthIndicator,
} from "@nestjs/terminus";
@Controller("api/v1/health")
export class HealthCheckController {
constructor(
private readonly health: HealthCheckService,
private readonly http: HttpHealthIndicator,
2020-05-03 04:32:14 +02:00
private readonly typeorm: TypeOrmHealthIndicator,
private readonly config: ConfigService
) {}
@Get()
@HealthCheck()
2021-05-25 18:12:42 +02:00
check(): Promise<HealthCheckResult> {
2020-05-03 04:32:14 +02:00
return this.health.check([
() =>
this.http.pingCheck(
2020-05-03 04:32:14 +02:00
"spotify-web",
this.config.get<string>("SPOTIFY_WEB_API_URL")
),
() =>
this.http.pingCheck(
2020-05-03 04:32:14 +02:00
"spotify-auth",
this.config.get<string>("SPOTIFY_AUTH_API_URL")
),
() => this.typeorm.pingCheck("db"),
]);
}
}