diff --git a/src/app/api/content/[collection]/route.ts b/src/app/api/content/[collection]/route.ts new file mode 100644 index 0000000..12ff68c --- /dev/null +++ b/src/app/api/content/[collection]/route.ts @@ -0,0 +1,24 @@ +import { NextRequest, NextResponse } from 'next/server' + +const VULA_CMS_URL = process.env.VULA_CMS_URL || 'https://ide.vulai.co.za' +const VULA_CMS_PROJECT_ID = process.env.VULA_CMS_PROJECT_ID || '3ba9e183-6d20-4dfd-bdbb-cd679f2f2a0c' + +export async function GET( + request: NextRequest, + { params }: { params: Promise<{ collection: string }> } +) { + const { collection } = await params + if (!VULA_CMS_PROJECT_ID) return NextResponse.json({ items: [] }) + try { + const { searchParams } = request.nextUrl + const status = searchParams.get('status') || 'published' + const limit = searchParams.get('limit') || '20' + const url = `${VULA_CMS_URL}/api/public/cms/${VULA_CMS_PROJECT_ID}/${collection}?status=${status}&limit=${limit}` + const res = await fetch(url, { cache: 'no-store' }) + if (!res.ok) return NextResponse.json({ items: [] }) + const json = await res.json() as { items?: unknown[] } + return NextResponse.json({ items: json.items ?? [] }) + } catch { + return NextResponse.json({ items: [] }) + } +}