From 0eabf151360f1d44e497e39b2c71d34cdfe7edff Mon Sep 17 00:00:00 2001 From: Ole Mathias Heggem Date: Mon, 7 Oct 2024 22:42:37 +0200 Subject: [PATCH] feat: add liveness endpoint for k8s --- package.json | 2 +- src/pages/liveness.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/pages/liveness.ts diff --git a/package.json b/package.json index 34edf99..4c1299a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "astro dev", "start": "astro dev", - "build": "astro check && export $(grep -v '^\\s*$\\|^\\s*\\#' .env.runtime) && printenv | grep API && astro build", + "build": "astro check && export $(grep -v '^\\s*$\\|^\\s*\\#' .env.runtime) && astro build", "preview": "astro preview", "astro": "astro" }, diff --git a/src/pages/liveness.ts b/src/pages/liveness.ts new file mode 100644 index 0000000..bb07e7d --- /dev/null +++ b/src/pages/liveness.ts @@ -0,0 +1,24 @@ +export const prerender = false; + +/** + * GET Request with JSON response + * @returns {Response} + */ +export async function GET() { + return new Response(JSON.stringify({ alive: true }), { + status: 200, + headers: { + "Content-Type": "application/json", + }, + }); +} + +/** + * HEAD Request + * @returns {Response} + */ +export function HEAD() { + return new Response(null, { + status: 204, + }); +}