Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/readyz.tsx
T

43 lines
1.2 KiB
TypeScript

import { loadWebConfig } from "@hivegrid/config";
import { assertPortalRlsRuntimeReady } from "@hivegrid/db/portal-rls-runtime-readiness.server";
import { db } from "~/utils/db.server";
import { checkCachedWebReadiness } from "~/utils/readiness-cache.server";
import { getWebServiceName } from "../../build-surface";
const checkDatabase = () => db.appConfiguration.count();
const checkPortalDatabaseRole = async () => {
const readiness = await assertPortalRlsRuntimeReady();
if (!readiness.ready) {
throw new Error("portal RLS readiness failed");
}
};
export const loader = async () => {
const { releaseRevision, runtimeSurface } = loadWebConfig().config;
const service = getWebServiceName(runtimeSurface);
try {
await checkCachedWebReadiness(runtimeSurface === "portal" ? checkPortalDatabaseRole : checkDatabase);
return Response.json(
{
status: "ready",
service,
surface: runtimeSurface,
revision: releaseRevision,
},
{ status: 200 }
);
} catch {
return Response.json(
{
status: "not_ready",
service,
surface: runtimeSurface,
revision: releaseRevision,
error: "database_unavailable",
},
{ status: 503 }
);
}
};