-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
55 lines (47 loc) · 1.37 KB
/
index.ts
File metadata and controls
55 lines (47 loc) · 1.37 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
53
54
55
import express, { type Request, type Response } from "express";
import {
Actuator,
HealthCheck,
SimpleHealthIndicator,
} from "@actuatorjs/actuatorjs";
import { checkPgPool } from "./src/health/checkPgPool";
import { pool } from "./src/config/pg";
import { PgHealthIndicator } from "./src/health/PgHealthIndicator";
export const pgHealthIndicator = new PgHealthIndicator(
"abstract-postgres",
pool,
);
export const simplePgHealthIndicator = new SimpleHealthIndicator(
"simple-postgres",
async () => {
return await checkPgPool(pool);
},
);
export const healthCheck = new HealthCheck([
pgHealthIndicator,
simplePgHealthIndicator,
]);
export const actuator = new Actuator(healthCheck);
const app = express();
const PORT = 3000;
app.get("/actuator/health", async (_req: Request, res: Response) => {
try {
const health = await actuator.getHealth();
res.json(health);
} catch (err) {
console.error("Failed to get health:", err);
res.status(500).json({ status: "DOWN", error: String(err) });
}
});
app.get("/actuator/info", async (_req: Request, res: Response) => {
try {
const info = await actuator.getInfo();
res.json(info);
} catch (err) {
console.error("Failed to get info:", err);
res.status(500).json({ error: String(err) });
}
})
app.listen(PORT, () => {
console.log(`Server listening on http://localhost:${PORT}`);
});