import {
  isPublicAuthPath,
  proxyToUpstream,
} from "@/lib/api/upstreamProxy";

type RouteContext = { params: Promise<{ path: string[] }> };

async function handle(req: Request, context: RouteContext) {
  const { path } = await context.params;
  const upstreamPath = `/api/v1/${path.join("/")}`;
  return proxyToUpstream(req, upstreamPath, {
    stripAuth: isPublicAuthPath(path),
  });
}

export const GET = handle;
export const POST = handle;
export const PUT = handle;
export const PATCH = handle;
export const DELETE = handle;
