24 lines
893 B
TypeScript
24 lines
893 B
TypeScript
import config from '@payload-config'
|
|||
|
|
import { getPayload } from 'payload'
|
||
|
|
|
||
|
|
export const dynamic = 'force-dynamic'
|
||
|
|
|
||
|
|
const TIMEOUT_MS = 3000
|
||
|
|
|
||
|
|
/** Проверка живости для выкладки и мониторинга: приложение отвечает и база доступна */
|
||
|
|
export async function GET() {
|
||
|
|
const headers = { 'Cache-Control': 'no-store' }
|
||
|
|
try {
|
||
|
|
const check = (async () => {
|
||
|
|
const payload = await getPayload({ config })
|
||
|
|
await payload.count({ collection: 'sites', overrideAccess: true })
|
||
|
|
})()
|
||
|
|
const timeout = new Promise<never>((_, reject) =>
|
||
|
|
setTimeout(() => reject(new Error('timeout')), TIMEOUT_MS),
|
||
|
|
)
|
||
|
|
await Promise.race([check, timeout])
|
||
|
|
return Response.json({ status: 'ok', db: 'ok' }, { headers })
|
||
|
|
} catch {
|
||
|
|
return Response.json({ status: 'error', db: 'unavailable' }, { status: 503, headers })
|
||
|
|
}
|
||
|
|
}
|