generated from hmcts/expressjs-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
31 lines (27 loc) · 817 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import config from 'config';
import { Application } from 'express';
const healthcheck = require('@hmcts/nodejs-healthcheck');
/**
* Sets up the HMCTS health endpoints
*/
export class HealthCheck {
public enableFor(app: Application): void {
const redis = app.locals.redisClient
? healthcheck.raw(() => (app.locals.redisClient.ping() ? healthcheck.up() : healthcheck.down()))
: null;
const idamUrl: string = process.env.IDAM_API_URL ?? config.get('services.idam.tokenURL');
healthcheck.addTo(app, {
checks: {
...(redis ? { redis } : {}),
'idam-api': healthcheck.web(new URL('/health', idamUrl.replace('/o/token', ''))),
},
...(redis
? {
readinessChecks: {
redis,
},
}
: {}),
});
}
}