2021-04-22 10:07:10 +02:00
|
|
|
import { Request, Response } from 'express';
|
|
|
|
import { IUnleashConfig } from '../types/option';
|
|
|
|
import { IUnleashServices } from '../types/services';
|
|
|
|
import { Logger } from '../logger';
|
2022-06-20 12:22:41 +02:00
|
|
|
import { OpenApiService } from '../services/openapi-service';
|
2021-04-22 10:07:10 +02:00
|
|
|
|
2022-06-20 12:22:41 +02:00
|
|
|
import Controller from './controller';
|
|
|
|
import { NONE } from '../types/permissions';
|
2022-07-01 08:06:33 +02:00
|
|
|
import { createResponseSchema } from '../openapi/util/create-response-schema';
|
2022-06-20 12:22:41 +02:00
|
|
|
import { HealthCheckSchema } from '../openapi/spec/health-check-schema';
|
2021-04-22 10:07:10 +02:00
|
|
|
|
2022-06-20 12:22:41 +02:00
|
|
|
export class HealthCheckController extends Controller {
|
2021-04-22 10:07:10 +02:00
|
|
|
private logger: Logger;
|
|
|
|
|
2022-06-20 12:22:41 +02:00
|
|
|
private openApiService: OpenApiService;
|
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
constructor(
|
|
|
|
config: IUnleashConfig,
|
2022-07-22 11:47:58 +02:00
|
|
|
{ openApiService }: Pick<IUnleashServices, 'openApiService'>,
|
2021-04-22 10:07:10 +02:00
|
|
|
) {
|
2021-08-13 10:36:19 +02:00
|
|
|
super(config);
|
2021-04-22 10:07:10 +02:00
|
|
|
this.logger = config.getLogger('health-check.js');
|
2022-06-20 12:22:41 +02:00
|
|
|
this.openApiService = openApiService;
|
|
|
|
|
|
|
|
this.route({
|
|
|
|
method: 'get',
|
|
|
|
path: '',
|
|
|
|
handler: this.getHealth,
|
|
|
|
permission: NONE,
|
|
|
|
middleware: [
|
|
|
|
openApiService.validPath({
|
2022-08-12 11:37:57 +02:00
|
|
|
tags: ['Operational'],
|
2022-06-20 12:22:41 +02:00
|
|
|
operationId: 'getHealth',
|
|
|
|
responses: {
|
|
|
|
200: createResponseSchema('healthCheckSchema'),
|
|
|
|
500: createResponseSchema('healthCheckSchema'),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
2021-04-22 10:07:10 +02:00
|
|
|
}
|
|
|
|
|
2022-06-20 12:22:41 +02:00
|
|
|
async getHealth(
|
|
|
|
_: Request,
|
|
|
|
res: Response<HealthCheckSchema>,
|
|
|
|
): Promise<void> {
|
2022-07-22 11:47:58 +02:00
|
|
|
res.status(200).json({ health: 'GOOD' });
|
2021-04-22 10:07:10 +02:00
|
|
|
}
|
|
|
|
}
|