forked from ryo-ma/github-profile-trophy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
49 lines (43 loc) · 1.34 KB
/
main.ts
File metadata and controls
49 lines (43 loc) · 1.34 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
import { serve } from "https://deno.land/std@0.125.0/http/server.ts";
import requestHandler from "./api/index.ts";
// Health check handler for Kubernetes probes
function healthHandler(request: Request): Response | null {
const url = new URL(request.url);
if (url.pathname === "/health" || url.pathname === "/healthz") {
return new Response(
JSON.stringify({
status: "ok",
timestamp: new Date().toISOString(),
}),
{
status: 200,
headers: { "Content-Type": "application/json" },
}
);
}
if (url.pathname === "/ready" || url.pathname === "/readyz") {
// Could add Redis connectivity check here if needed
return new Response(
JSON.stringify({
status: "ready",
timestamp: new Date().toISOString(),
}),
{
status: 200,
headers: { "Content-Type": "application/json" },
}
);
}
return null;
}
// Combined handler - check health first, then delegate to main handler
function combinedHandler(request: Request): Response | Promise<Response> {
const healthResponse = healthHandler(request);
if (healthResponse) {
return healthResponse;
}
return requestHandler(request);
}
const port = Number(Deno.env.get("PORT")) || 8080;
console.log(`Starting github-profile-trophy server on port ${port}`);
serve(combinedHandler, { port });