mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2026-03-21 22:56:47 +00:00
* Upgrade to nextjs 16 * Update sentry config * Force dynamic for health route * Upgrade eslint config * Upgrade jest * Move types to dev dependencies * Remove pages from tailwind config * Replace img with next image
41 lines
995 B
TypeScript
41 lines
995 B
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET() {
|
|
const health = {
|
|
status: "healthy",
|
|
timestamp: new Date().toISOString(),
|
|
uptime: process.uptime(),
|
|
environment: process.env.NODE_ENV,
|
|
checks: {
|
|
redis: await checkRedis(),
|
|
},
|
|
};
|
|
|
|
const allHealthy = Object.values(health.checks).every((check) => check);
|
|
|
|
return NextResponse.json(health, {
|
|
status: allHealthy ? 200 : 503,
|
|
});
|
|
}
|
|
|
|
async function checkRedis(): Promise<boolean> {
|
|
try {
|
|
if (!process.env.KV_URL) {
|
|
return false;
|
|
}
|
|
|
|
const { tokenCacheRedis } = await import("../../lib/redisClient");
|
|
const testKey = `health:check:${Date.now()}`;
|
|
await tokenCacheRedis.setex(testKey, 10, "OK");
|
|
const value = await tokenCacheRedis.get(testKey);
|
|
await tokenCacheRedis.del(testKey);
|
|
|
|
return value === "OK";
|
|
} catch (error) {
|
|
console.error("Redis health check failed:", error);
|
|
return false;
|
|
}
|
|
}
|