feat: debug endpoint
Build and Push Image / build-backend (push) Successful in 2m50s
Build and Push Image / build-frontend (push) Successful in 4m4s
Build and Push Image / push (push) Successful in 1m7s

This commit is contained in:
2026-07-27 11:40:02 +07:00 Unverified
parent e3133d0cd3
commit e73c05f7d2
+92
View File
@@ -0,0 +1,92 @@
import { adminCheck } from "@/lib/auth";
import { db } from "@/lib/db";
import { redis } from "@/lib/db/redis";
import { env } from "bun";
import { sql } from "drizzle-orm";
async function probe(name: string, fn: () => Promise<unknown>) {
const started = performance.now();
try {
const result = await fn();
return {
name,
ok: true,
latencyMs: performance.now() - started,
result,
};
} catch (error) {
return {
name,
ok: false,
latencyMs: performance.now() - started,
error:
error instanceof Error
? {
name: error.name,
message: error.message,
stack: error.stack,
cause: error.cause,
}
: error,
};
}
}
export async function GET(request: Request) {
if (!adminCheck()) {
return new Response("Unauthorized", { status: 401 });
}
const probes = await Promise.all([
probe("redis", async () => {
const started = performance.now();
const result = await redis?.ping();
return {
result,
latencyMs: performance.now() - started,
};
}),
probe("postgres", async () => {
const started = performance.now();
const result = await db.execute(sql`SELECT 1`);
return {
result,
latencyMs: performance.now() - started,
};
}),
]);
return Response.json({
timestamp: new Date().toISOString(),
runtime: {
bun: Bun.version,
node: process.version,
platform: process.platform,
arch: process.arch,
pid: process.pid,
uptime: process.uptime(),
cwd: process.cwd(),
},
memory: process.memoryUsage(),
eventLoop: {
now: performance.now(),
},
request: {
url: request.url,
headers: Object.fromEntries(request.headers),
},
env,
probes,
});
}