This commit is contained in:
Vula Builder
2026-08-01 17:20:29 +00:00
parent 683cf18724
commit bff5718148
+23
View File
@@ -0,0 +1,23 @@
import { NextRequest, NextResponse } from 'next/server'
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url)
const rawLimit = searchParams.get('limit') || '12'
const parsedLimit = parseInt(rawLimit, 10)
const limit = isNaN(parsedLimit) ? 12 : Math.min(Math.max(parsedLimit, 1), 100)
const categoryId = searchParams.get('categoryId') || undefined
const ids = searchParams.getAll('id[]')
const vulaUrl = process.env.VULA_CMS_URL || 'https://ide.vulai.co.za'
const projectId = process.env.VULA_CMS_PROJECT_ID || ''
const params = new URLSearchParams({ limit: String(limit) })
if (categoryId) params.set('category_id', categoryId)
ids.forEach(id => params.append('id[]', id))
try {
const r = await fetch(`${vulaUrl}/api/store/${projectId}/products?${params}`, { cache: 'no-store' })
const data = await r.json()
return NextResponse.json(data)
} catch {
return NextResponse.json({ success: false, products: [], count: 0 }, { status: 502 })
}
}