import config from '@payload-config'
import { getPayload } from 'payload'

export const dynamic = 'force-dynamic'

// For the container health check: the app answers and the database is reachable.
export async function GET() {
  try {
    const payload = await getPayload({ config })
    const { totalDocs } = await payload.count({ collection: 'courses' })
    return Response.json({ ok: true, courses: totalDocs })
  } catch {
    return Response.json({ ok: false }, { status: 503 })
  }
}
