node: implement live & ready check helpers

This commit is contained in:
Elijah Duffy
2025-12-24 18:12:57 -08:00
parent 85b698d940
commit d88c1c0c49
3 changed files with 232 additions and 30 deletions

View File

@@ -0,0 +1,31 @@
/**
* 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' },
});
};