import { NextResponse } from 'next/server'; import { childrenOf } from '@/lib/queries/taxonomy'; export const dynamic = 'force-dynamic'; /** Lazily fetch children of a node for the tree browser. GET /api/taxonomy/children?id=CI-CAN-…&type=oncotree */ export async function GET(req: Request) { const url = new URL(req.url); const id = url.searchParams.get('id') ?? ''; const type = url.searchParams.get('type') ?? 'ncit'; if (!/^CI-CAN-\d{8,}$/.test(id)) return NextResponse.json({ error: 'invalid id' }, { status: 400 }); if (!/^[a-z_]{2,24}$/.test(type)) return NextResponse.json({ error: 'invalid type' }, { status: 400 }); const data = await childrenOf(id, type); return NextResponse.json({ data }, { headers: { 'Cache-Control': 'public, max-age=300, s-maxage=3600' } }); }