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
19
package-lock.json
generated
19
package-lock.json
generated
|
|
@ -1396,6 +1396,15 @@
|
||||||
"path-to-regexp": "3.2.0"
|
"path-to-regexp": "3.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@nestjs/terminus": {
|
||||||
|
"version": "7.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@nestjs/terminus/-/terminus-7.0.1.tgz",
|
||||||
|
"integrity": "sha512-OKg1QQDb+whHJM3Xt+3RRUPiyZSyD0qLacfldK0TXcFpKyexA0yyY3GKeaBNApf01FEzJgkK3ARCUoELnAfXDA==",
|
||||||
|
"requires": {
|
||||||
|
"check-disk-space": "2.1.0",
|
||||||
|
"deprecate": "^1.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@nestjs/testing": {
|
"@nestjs/testing": {
|
||||||
"version": "7.0.9",
|
"version": "7.0.9",
|
||||||
"resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-7.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-7.0.9.tgz",
|
||||||
|
|
@ -2864,6 +2873,11 @@
|
||||||
"integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==",
|
"integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"check-disk-space": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/check-disk-space/-/check-disk-space-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-f0nx9oJF/AVF8nhSYlF1EBvMNnO+CXyLwKhPvN1943iOMI9TWhQigLZm80jAf0wzQhwKkzA8XXjyvuVUeGGcVQ=="
|
||||||
|
},
|
||||||
"chokidar": {
|
"chokidar": {
|
||||||
"version": "3.3.1",
|
"version": "3.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.3.1.tgz",
|
||||||
|
|
@ -3672,6 +3686,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||||
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
|
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
|
||||||
},
|
},
|
||||||
|
"deprecate": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/deprecate/-/deprecate-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-ZGDXefq1xknT292LnorMY5s8UVU08/WKdzDZCUT6t9JzsiMSP4uzUhgpqugffNVcT5WC6wMBiSQ+LFjlv3v7iQ=="
|
||||||
|
},
|
||||||
"des.js": {
|
"des.js": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz",
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
"@nestjs/schedule": "^0.3.1",
|
"@nestjs/schedule": "^0.3.1",
|
||||||
"@nestjs/serve-static": "^2.1.0",
|
"@nestjs/serve-static": "^2.1.0",
|
||||||
"@nestjs/swagger": "^4.5.3",
|
"@nestjs/swagger": "^4.5.3",
|
||||||
|
"@nestjs/terminus": "^7.0.1",
|
||||||
"@nestjs/typeorm": "^7.0.0",
|
"@nestjs/typeorm": "^7.0.0",
|
||||||
"class-transformer": "^0.2.3",
|
"class-transformer": "^0.2.3",
|
||||||
"class-validator": "^0.12.2",
|
"class-validator": "^0.12.2",
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import { MusicLibraryModule } from "./music-library/music-library.module";
|
||||||
import { SourcesModule } from "./sources/sources.module";
|
import { SourcesModule } from "./sources/sources.module";
|
||||||
import { UsersModule } from "./users/users.module";
|
import { UsersModule } from "./users/users.module";
|
||||||
import { ConfigModule } from "./config/config.module";
|
import { ConfigModule } from "./config/config.module";
|
||||||
|
import { HealthCheckModule } from "./health-check/health-check.module";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
|
@ -26,6 +27,7 @@ import { ConfigModule } from "./config/config.module";
|
||||||
SourcesModule,
|
SourcesModule,
|
||||||
MusicLibraryModule,
|
MusicLibraryModule,
|
||||||
ListensModule,
|
ListensModule,
|
||||||
|
HealthCheckModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
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