node: implement live & ready check helpers
This commit is contained in:
31
node-health/src/liveness.ts
Normal file
31
node-health/src/liveness.ts
Normal 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' },
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user