import { NextRequest, NextResponse } from 'next/server'; import { getSnippets } from '@/lib/directus'; const CACHE_TTL = 300; // 5 minutes export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url); const limit = parseInt(searchParams.get('limit') || '10'); const featured = searchParams.get('featured') === 'true' ? true : undefined; const snippets = await getSnippets(limit, featured); return NextResponse.json( { snippets: snippets || [] }, { headers: { 'Cache-Control': `public, s-maxage=${CACHE_TTL}, stale-while-revalidate=${CACHE_TTL * 2}` } } ); } catch (_error) { return NextResponse.json({ error: 'Failed to fetch snippets' }, { status: 500 }); } }