From a241024ced1e2f91c31cf4619495c728acf16f48 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Tue, 14 Apr 2026 22:48:00 -0600 Subject: [PATCH] use middleware for runtime backend proxy --- web/middleware.js | 11 +++++++++++ web/next.config.mjs | 8 -------- 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 web/middleware.js diff --git a/web/middleware.js b/web/middleware.js new file mode 100644 index 00000000..8681f728 --- /dev/null +++ b/web/middleware.js @@ -0,0 +1,11 @@ +import { NextResponse } from 'next/server' + +export function middleware(request) { + const backendUrl = process.env.BACKEND_URL || 'http://localhost:8080' + const { pathname, search } = request.nextUrl + return NextResponse.rewrite(new URL(pathname + search, backendUrl)) +} + +export const config = { + matcher: '/api/:path*', +} diff --git a/web/next.config.mjs b/web/next.config.mjs index 77d89061..2a1407d5 100644 --- a/web/next.config.mjs +++ b/web/next.config.mjs @@ -2,14 +2,6 @@ const nextConfig = { output: 'standalone', reactCompiler: true, - async rewrites() { - return [ - { - source: "/api/:path*", - destination: `${process.env.BACKEND_URL || "http://localhost:8080"}/api/:path*`, - }, - ]; - }, }; export default nextConfig;