mighttguy commited on
Commit
229d9db
·
1 Parent(s): 2507900

adding keep-alive endpoint

Browse files
src/config/routes.ts CHANGED
@@ -9,6 +9,10 @@ export interface RouteConfig {
9
  }
10
 
11
  export const routeConfigs: RouteConfig[] = [
 
 
 
 
12
  {
13
  path: "/api/ws/ticket",
14
  rules: [{ method: "ALL", protected: true }],
 
9
  }
10
 
11
  export const routeConfigs: RouteConfig[] = [
12
+ {
13
+ path: "/api/ws/keep-alive",
14
+ rules: [{ method: "GET", protected: false }],
15
+ },
16
  {
17
  path: "/api/ws/ticket",
18
  rules: [{ method: "ALL", protected: true }],
src/config/select-rate-limiter.ts CHANGED
@@ -14,7 +14,7 @@ export const selectRateLimiter = (
14
  const path = req.originalUrl;
15
  const method = req.method;
16
 
17
- if (path.startsWith("/api/health")) {
18
  return next();
19
  }
20
  if (
 
14
  const path = req.originalUrl;
15
  const method = req.method;
16
 
17
+ if (path.startsWith("/api/health") || path.startsWith("/api/keep-alive")) {
18
  return next();
19
  }
20
  if (
src/index.ts CHANGED
@@ -17,6 +17,9 @@ import { routeConfigs } from "./config/routes";
17
  import { env } from "./config/env";
18
  import { currentUser } from "./lib/utils/get-current-user";
19
  import { selectRateLimiter } from "./config/select-rate-limiter";
 
 
 
20
 
21
  const app = express();
22
 
@@ -26,6 +29,7 @@ app.use(
26
  credentials: true,
27
  }),
28
  );
 
29
  app.use(requestLogger);
30
  app.use(express.json());
31
 
@@ -63,6 +67,26 @@ app.use(selectRateLimiter);
63
 
64
  app.all("/api/auth/{*any}", toNodeHandler(auth));
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  app.use("/api/games", gameRouter);
67
  app.use("/api/friends", friendRouter);
68
  app.use("/api/chat", chatRouter);
 
17
  import { env } from "./config/env";
18
  import { currentUser } from "./lib/utils/get-current-user";
19
  import { selectRateLimiter } from "./config/select-rate-limiter";
20
+ import { db } from "./infrastructure/db/db";
21
+ import { sql } from "drizzle-orm";
22
+ import { redis } from "./infrastructure/redis/redis-client";
23
 
24
  const app = express();
25
 
 
29
  credentials: true,
30
  }),
31
  );
32
+
33
  app.use(requestLogger);
34
  app.use(express.json());
35
 
 
67
 
68
  app.all("/api/auth/{*any}", toNodeHandler(auth));
69
 
70
+ app.get("/api/keep-alive", async (req, res) => {
71
+ try {
72
+ await db.execute(sql`SELECT 1`);
73
+ const redisPing = await redis.ping();
74
+
75
+ if (redisPing !== "PONG") {
76
+ throw new Error("Redis did not respond with PONG");
77
+ }
78
+
79
+ return res.status(200).json({
80
+ status: "awake",
81
+ db: "active",
82
+ redis: "active",
83
+ timestamp: new Date().toISOString(),
84
+ });
85
+ } catch (err) {
86
+ console.error("Keep-alive failed:", err);
87
+ }
88
+ });
89
+
90
  app.use("/api/games", gameRouter);
91
  app.use("/api/friends", friendRouter);
92
  app.use("/api/chat", chatRouter);