forked from LF-Decentralized-Trust-labs/gitmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth.ts
More file actions
52 lines (47 loc) · 1.41 KB
/
Copy pathhealth.ts
File metadata and controls
52 lines (47 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Router } from "express";
import type { Db } from "@gitmesh/data";
import { count, sql } from "@gitmesh/data";
import { instanceUserRoles } from "@gitmesh/data";
import type { DeploymentExposure, DeploymentMode } from "@gitmesh/core";
export function healthRoutes(
db?: Db,
opts: {
deploymentMode: DeploymentMode;
deploymentExposure: DeploymentExposure;
authReady: boolean;
projectDeletionEnabled: boolean;
} = {
deploymentMode: "local_trusted",
deploymentExposure: "private",
authReady: true,
projectDeletionEnabled: true,
},
) {
const router = Router();
router.get("/", async (_req, res) => {
if (!db) {
res.json({ status: "ok" });
return;
}
let bootstrapStatus: "ready" | "bootstrap_pending" = "ready";
if (opts.deploymentMode === "authenticated") {
const roleCount = await db
.select({ count: count() })
.from(instanceUserRoles)
.where(sql`${instanceUserRoles.role} = 'instance_admin'`)
.then((rows) => Number(rows[0]?.count ?? 0));
bootstrapStatus = roleCount > 0 ? "ready" : "bootstrap_pending";
}
res.json({
status: "ok",
deploymentMode: opts.deploymentMode,
deploymentExposure: opts.deploymentExposure,
authReady: opts.authReady,
bootstrapStatus,
features: {
projectDeletionEnabled: opts.projectDeletionEnabled,
},
});
});
return router;
}