fix: api-proxy per middleware (laufzeit-env statt build-time rewrites)
CI / backend-tests (push) Successful in 9s
Docker images / version (push) Successful in 1s
CI / docker (push) Successful in 21s
Docker images / backend (push) Successful in 5s
Docker images / frontend (push) Successful in 6s

This commit is contained in:
loki committed 2026-10-04 13:52:18 +02:00
1 parent 4b915d3b52
commit df654fcb92
2 files changed
+17

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
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*",
};
+2
View File
@@ -9,6 +9,8 @@ const nextConfig = {
],
},
async rewrites() {
// Dev fallback only. In Docker/standalone the middleware.ts proxy handles
// /api/* with the runtime BACKEND_URL (rewrites are build-time there).
const backend = process.env.BACKEND_URL || "http://127.0.0.1:8000";
return [
{ source: "/api/:path*", destination: `${backend}/api/:path*` },