-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): Add health check against the backend to cover both the …
…client and backend
- Loading branch information
Showing
1 changed file
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }, | ||
}); | ||
} | ||
} |