diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index a167361..a17bdc3 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -10,10 +10,6 @@ const nextConfig = { }, async rewrites() { return [ - { - source: "/files/:path*", - destination: `${BACKEND_INTERNAL_URL}/files/:path*` - }, { source: "/api/:path*", destination: `${BACKEND_INTERNAL_URL}/api/:path*` diff --git a/frontend/src/app/files/[...path]/route.ts b/frontend/src/app/files/[...path]/route.ts new file mode 100644 index 0000000..6f95406 --- /dev/null +++ b/frontend/src/app/files/[...path]/route.ts @@ -0,0 +1,35 @@ +import { NextRequest, NextResponse } from "next/server"; + +export const runtime = "nodejs"; +export const dynamic = "force-dynamic"; + +const BACKEND = + process.env.BACKEND_INTERNAL_URL || "http://localhost:20001"; + +export async function GET( + _req: NextRequest, + { params }: { params: Promise<{ path: string[] }> } +) { + const { path } = await params; + const url = `${BACKEND}/files/${path.join("/")}`; + + let res: Response; + try { + res = await fetch(url, { cache: "no-store" }); + } catch { + return new NextResponse("Bad Gateway", { status: 502 }); + } + + if (!res.ok) { + return new NextResponse(null, { status: res.status }); + } + + const body = await res.arrayBuffer(); + return new NextResponse(body, { + headers: { + "Content-Type": + res.headers.get("Content-Type") ?? "application/octet-stream", + "Cache-Control": "public, max-age=31536000, immutable", + }, + }); +}