-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathhealth-check.ts
52 lines (46 loc) · 1.91 KB
/
health-check.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { Request, Response } from 'express';
import type { IUnleashConfig } from '../types/option';
import type { IUnleashServices } from '../types/services';
import type { Logger } from '../logger';
import type { OpenApiService } from '../services/openapi-service';
import Controller from './controller';
import { NONE } from '../types/permissions';
import { createResponseSchema } from '../openapi/util/create-response-schema';
import type { HealthCheckSchema } from '../openapi/spec/health-check-schema';
export class HealthCheckController extends Controller {
private logger: Logger;
private openApiService: OpenApiService;
constructor(
config: IUnleashConfig,
{ openApiService }: Pick<IUnleashServices, 'openApiService'>,
) {
super(config);
this.logger = config.getLogger('health-check.js');
this.openApiService = openApiService;
this.route({
method: 'get',
path: '',
handler: this.getHealth,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Operational'],
operationId: 'getHealth',
summary: 'Get instance operational status',
description:
'This operation returns information about whether this Unleash instance is healthy and ready to serve requests or not. Typically used by your deployment orchestrator (e.g. Kubernetes, Docker Swarm, Mesos, et al.).',
responses: {
200: createResponseSchema('healthCheckSchema'),
500: createResponseSchema('healthCheckSchema'),
},
}),
],
});
}
async getHealth(
_: Request,
res: Response<HealthCheckSchema>,
): Promise<void> {
res.status(200).json({ health: 'GOOD' });
}
}