Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 2x 2x 2x 2x 2x 2x 2x 6x 6x 5x 5x 5x 1x 1x | export const dynamic = "force-dynamic";
import { NextRequest, NextResponse } from "next/server";
import { getSearchSuggestions } from "@/lib/search";
import { addSecurityHeaders } from "@/lib/security";
import {
withErrorHandling,
successResponse,
ApiSuccessResponse } from "@/lib/api";
/**
* GET /api/products/search/suggestions
* Get search suggestions based on query
*/
async function handleGet(
request: NextRequest
): Promise<NextResponse<ApiSuccessResponse<string[]>>> {
const searchParams = request.nextUrl.searchParams;
const query = searchParams.get("query");
const limit = parseInt(searchParams.get("limit") || "10");
if (!query || query.length < 2) {
return addSecurityHeaders(
NextResponse.json({
success: true,
data: [],
message: "Query must be at least 2 characters"})
) as NextResponse<ApiSuccessResponse<string[]>>;
}
const suggestions = await getSearchSuggestions(query, limit);
return addSecurityHeaders(successResponse(suggestions)) as NextResponse<ApiSuccessResponse<string[]>>;
}
export const GET = withErrorHandling(handleGet);
|