1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/src/lib/routes/health-check.ts
Christopher Kolstad 7003351b35
docs: Health check endpoint (#3959)
### What
Adds documentation for the health check endpoint.

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-06-12 12:56:45 +00:00

53 lines
1.9 KiB
TypeScript

import { Request, Response } from 'express';
import { IUnleashConfig } from '../types/option';
import { IUnleashServices } from '../types/services';
import { Logger } from '../logger';
import { OpenApiService } from '../services/openapi-service';
import Controller from './controller';
import { NONE } from '../types/permissions';
import { createResponseSchema } from '../openapi/util/create-response-schema';
import { 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' });
}
}