Files
health/node-health/src/liveness.ts
2025-12-24 18:12:57 -08:00

32 lines
762 B
TypeScript

/**
* Type representing the result of a liveness check.
*/
export type LivenessResult = {
/** Status of the service (always 'ok'). */
status: 'ok';
/** Timestamp of the liveness check in milliseconds since the Unix epoch. */
timestamp: number;
};
/**
* Liveness check - indicates if the service is running.
* @returns A LivenessResult object.
*/
export function liveness() {
return {
status: 'ok',
timestamp: Date.now(),
} as LivenessResult;
}
/**
* Handler for liveness HTTP requests.
* @returns A Response object with LivenessResult in JSON format and status 200.
*/
export const handleLiveness = (): Response => {
return new Response(JSON.stringify(liveness()), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
};