From 9d275812301dbb55262d53519c9a9182b9aaf3ee Mon Sep 17 00:00:00 2001 From: Alejandro Peralta Date: Fri, 22 Nov 2024 13:56:49 +0100 Subject: [PATCH] feat(client): Add /health endpoint to the client app --- client/src/app/local-api/health/route.ts | 25 +++++++++++++++++++++ client/src/middleware.ts | 2 +- infrastructure/v2/modules/beanstalk/main.tf | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 client/src/app/local-api/health/route.ts diff --git a/client/src/app/local-api/health/route.ts b/client/src/app/local-api/health/route.ts new file mode 100644 index 00000000..175fda74 --- /dev/null +++ b/client/src/app/local-api/health/route.ts @@ -0,0 +1,25 @@ +import { env } from "@/env.mjs"; + +export async function GET() { + 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" }, + }); + } +} diff --git a/client/src/middleware.ts b/client/src/middleware.ts index c14b735e..174ef718 100644 --- a/client/src/middleware.ts +++ b/client/src/middleware.ts @@ -41,5 +41,5 @@ function isAuthenticated(req: NextRequest) { // Step 3. Configure "Matching Paths" below to protect routes with HTTP Basic Auth export const config = { - matcher: "/((?!api|_next/static|_next/image|favicon.ico).*)", + matcher: "/((?!local-api|_next/static|_next/image|favicon.ico).*)", }; diff --git a/infrastructure/v2/modules/beanstalk/main.tf b/infrastructure/v2/modules/beanstalk/main.tf index da45c207..8b4cfd51 100644 --- a/infrastructure/v2/modules/beanstalk/main.tf +++ b/infrastructure/v2/modules/beanstalk/main.tf @@ -171,7 +171,7 @@ locals { { namespace = "aws:elasticbeanstalk:environment:process:default" name = "HealthCheckPath" - value = "/health" + value = "/local-apì/health" } ] }