Deploy
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user