Publish Meshkee sitemap-config, map product-source specials without variants, restore hero autoplay, and tighten page heroes, product images, and section order. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { meshkeeApiBase, websiteDomain } from "@/lib/config";
|
|
|
|
export async function GET(request: Request) {
|
|
const url = new URL(request.url);
|
|
const query = url.searchParams.get("q")?.trim() ?? "";
|
|
if (query.length <= 2) {
|
|
return Response.json({ items: [] });
|
|
}
|
|
|
|
const encoded = encodeURIComponent(query);
|
|
const base = `${meshkeeApiBase}/tenants/${encodeURIComponent(websiteDomain)}`;
|
|
|
|
try {
|
|
const storeResponse = await fetch(`${base}/store-items?name=${encoded}&pageSize=8`, {
|
|
cache: "no-store",
|
|
});
|
|
const storeData = (await storeResponse.json()) as { items?: unknown[] };
|
|
if (storeData.items?.length) {
|
|
return Response.json(storeData);
|
|
}
|
|
|
|
const catalogResponse = await fetch(`${base}/products?name=${encoded}&pageSize=8`, {
|
|
cache: "no-store",
|
|
});
|
|
const catalogData = (await catalogResponse.json()) as {
|
|
items?: Array<{
|
|
id: string;
|
|
nameFa?: string | null;
|
|
title?: string | null;
|
|
slug?: string | null;
|
|
thumbnailUrl?: string | null;
|
|
image?: string | null;
|
|
store?: { minPrice?: number | null; maxPrice?: number | null };
|
|
}>;
|
|
};
|
|
|
|
return Response.json({
|
|
items: (catalogData.items ?? []).map((item) => ({
|
|
id: item.slug || item.id,
|
|
productId: item.id,
|
|
productNameFa: item.nameFa,
|
|
productTitle: item.title,
|
|
productImage: item.thumbnailUrl || item.image,
|
|
price: item.store?.minPrice ?? item.store?.maxPrice ?? null,
|
|
})),
|
|
});
|
|
} catch {
|
|
return Response.json({ items: [] });
|
|
}
|
|
}
|