SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
709 B · 17 lines typescript
Raw Blame History
1import { NextResponse } from 'next/server';2import { suggest } from '@rareindex/search';34export const dynamic = 'force-dynamic';56export async function GET(req: Request) {7  const { searchParams } = new URL(req.url);8  const q = (searchParams.get('q') ?? '').slice(0, 80);9  if (q.trim().length < 2) return NextResponse.json({ items: [] }, { headers: { 'cache-control': 'public, max-age=30' } });10  try {11    const items = await suggest(q, 8);12    return NextResponse.json({ items }, { headers: { 'cache-control': 'public, max-age=60, stale-while-revalidate=300' } });13  } catch (err) {14    return NextResponse.json({ items: [], error: err instanceof Error ? err.message : 'error' }, { status: 200 });15  }16}17