/opt/canhelp/apps/api/src/routes
Edit: /opt/canhelp/apps/api/src/routes/health.ts (1214B)
import { Hono } from 'hono'
import { db } from '../db.js'
import { redis } from '../redis.js'
import { sql } from 'drizzle-orm'
import { getAppleClientSecretExpDebugInfo } from '../lib/apple-client-secret.js'
const app = new Hono()
const healthDebugToken = process.env.HEALTH_DEBUG_TOKEN?.trim()
app.get('/', async (c) => {
let dbOk = false
let redisOk = false
try {
await db.execute(sql`SELECT 1`)
dbOk = true
} catch {}
try {
await redis.ping()
redisOk = true
} catch {}
const status = dbOk && redisOk ? 200 : 503
return c.json({ status: status === 200 ? 'ok' : 'degraded', db: dbOk, redis: redisOk }, status)
})
app.get('/debug', async (c) => {
// Secure-by-default: endpoint stays unavailable until token is configured.
if (!healthDebugToken) {
return c.json({ error: 'Not found' }, 404)
}
const token = c.req.header('X-Debug-Token')?.trim()
if (!token || token !== healthDebugToken) {
return c.json({ error: 'Unauthorized' }, 401)
}
const appleJwt = getAppleClientSecretExpDebugInfo()
console.log('[Health Debug] Apple JWT exp:', appleJwt.expIso ?? 'n/a', 'configured:', appleJwt.configured)
return c.json({ appleJwt })
})
export default app