import { NextRequest, NextResponse } from 'next/server';

const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';

export async function GET(request: NextRequest) {
  const { searchParams } = new URL(request.url);
  const qs = searchParams.toString();
  const url = `${API}/shipping/methods${qs ? `?${qs}` : ''}`;
  try {
    const res = await fetch(url, { cache: 'no-store' });
    const body = await res.json().catch(() => ({ items: [] }));
    return NextResponse.json(body, { status: res.status });
  } catch {
    return NextResponse.json({ items: [] }, { status: 502 });
  }
}