import { NextResponse } from "next/server";
import { getProducts } from "../../lib/payload";

// Same-origin proxy for client components (CartContent, RelatedProducts)
// that need the full catalog reactively — Payload's own API is public-read
// and CORS wouldn't be a blocker, but going through the app's own origin
// avoids depending on that, reuses Next.js's fetch cache from getProducts()
// (no extra round trip to Payload beyond the first request within the 60s
// revalidate window), and keeps the Payload URL itself as a server-only
// implementation detail the client never talks to directly.
export async function GET() {
  const products = await getProducts();
  return NextResponse.json(products);
}
