import { sql } from "drizzle-orm"; import { youtubeCache } from "@/lib/adaptive-cache"; import { adminCheck } from "@/lib/auth"; import { db } from "@/lib/db"; import { redis } from "@/lib/db/redis"; import { createDebugHandler } from "./handler"; const timeoutMs = 5_000; export const GET = createDebugHandler({ adminCheck, runtime: () => ({ bun: Bun.version, node: process.version, platform: process.platform, arch: process.arch, uptime: process.uptime(), }), memoryUsage: () => process.memoryUsage(), probes: [ { name: "redis", run: () => withTimeout(redis!.ping(), timeoutMs), }, { name: "postgres", run: () => withTimeout(db.execute(sql`SELECT 1`), timeoutMs), }, { name: "youtubeCache", run: () => withTimeout(youtubeCache.debugStats(), timeoutMs), }, ], }); async function withTimeout(promise: Promise, ms: number): Promise { let timeout: ReturnType; try { return await Promise.race([ promise, new Promise((_, reject) => { timeout = setTimeout(() => reject(new Error("Probe timed out")), ms); }), ]); } finally { clearTimeout(timeout!); } }