mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(api): add health-check endpoint
This commit is contained in:
parent
e78c6e312d
commit
202665a510
5 changed files with 64 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import { MusicLibraryModule } from "./music-library/music-library.module";
|
|||
import { SourcesModule } from "./sources/sources.module";
|
||||
import { UsersModule } from "./users/users.module";
|
||||
import { ConfigModule } from "./config/config.module";
|
||||
import { HealthCheckModule } from "./health-check/health-check.module";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -26,6 +27,7 @@ import { ConfigModule } from "./config/config.module";
|
|||
SourcesModule,
|
||||
MusicLibraryModule,
|
||||
ListensModule,
|
||||
HealthCheckModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
|
|
|||
36
src/health-check/health-check.controller.ts
Normal file
36
src/health-check/health-check.controller.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { Controller, Get } from "@nestjs/common";
|
||||
import {
|
||||
DNSHealthIndicator,
|
||||
HealthCheck,
|
||||
HealthCheckService,
|
||||
TypeOrmHealthIndicator,
|
||||
} from "@nestjs/terminus";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
|
||||
@Controller("api/v1/health")
|
||||
export class HealthCheckController {
|
||||
constructor(
|
||||
private readonly health: HealthCheckService,
|
||||
private readonly dns: DNSHealthIndicator,
|
||||
private readonly typeorm: TypeOrmHealthIndicator,
|
||||
private readonly config: ConfigService
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@HealthCheck()
|
||||
check() {
|
||||
return this.health.check([
|
||||
() =>
|
||||
this.dns.pingCheck(
|
||||
"spotify-web",
|
||||
this.config.get<string>("SPOTIFY_WEB_API_URL")
|
||||
),
|
||||
() =>
|
||||
this.dns.pingCheck(
|
||||
"spotify-auth",
|
||||
this.config.get<string>("SPOTIFY_AUTH_API_URL")
|
||||
),
|
||||
() => this.typeorm.pingCheck("db"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
6
src/health-check/health-check.module.ts
Normal file
6
src/health-check/health-check.module.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { Module } from "@nestjs/common";
|
||||
import { TerminusModule } from "@nestjs/terminus";
|
||||
import { HealthCheckController } from "./health-check.controller";
|
||||
|
||||
@Module({ imports: [TerminusModule], controllers: [HealthCheckController] })
|
||||
export class HealthCheckModule {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue