16 lines
589 B
TypeScript
16 lines
589 B
TypeScript
import { NextResponse } from "next/server";
|
|
import type { NextRequest } from "next/server";
|
|
|
|
// Proxies /api/* to the backend. Runs per request, so BACKEND_URL is read
|
|
// at RUNTIME (unlike next.config.js rewrites, which are baked at build time
|
|
// in standalone mode and ignore container env vars).
|
|
export function middleware(req: NextRequest) {
|
|
const backend = process.env.BACKEND_URL || "http://127.0.0.1:8000";
|
|
const target = new URL(req.nextUrl.pathname + req.nextUrl.search, backend);
|
|
return NextResponse.rewrite(target);
|
|
}
|
|
|
|
export const config = {
|
|
matcher: "/api/:path*",
|
|
};
|