Skip to content

Commit

Permalink
feat(client): Add health check against the backend to cover both the …
Browse files Browse the repository at this point in the history
…client and backend
  • Loading branch information
alepefe committed Nov 4, 2024
1 parent d440e49 commit ddc8d07
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions client/src/app/health/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
// ? this endpoint is used as health check for the application
import { env } from "@/env";

export async function GET() {
return new Response("OK", { status: 200 });
try {
const res = await fetch(env.NEXT_PUBLIC_API_URL + "/health", {
cache: "no-cache",
});
if (res.status === 200) {
return new Response("OK", {
status: 200,
headers: { "Cache-Control": "max-age=5, must-revalidate" },
});
} else {
return new Response("KO", {
status: 503,
headers: { "Cache-Control": "max-age=5, must-revalidate" },
});
}
} catch (error) {
return new Response("KO", {
status: 503,
headers: { "Cache-Control": "max-age=5, must-revalidate" },
});
}
}

0 comments on commit ddc8d07

Please sign in to comment.