Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

Fix #838: Use Next.js Middleware for dynamic proxying of API routes (#839)

SAI KISHAN A8892d835ea03
diff --git a/packages/web/next.config.ts b/packages/web/next.config.ts
index 3411c9bc3..a3ecd0d93 100644
--- a/packages/web/next.config.ts
+++ b/packages/web/next.config.ts
@@ -24,23 +24,6 @@ const nextConfig: NextConfig = {
images: {
unoptimized: true,
},
- async rewrites() {
- const apiUrl = process.env.REPOWISE_API_URL || "http://localhost:7337";
- return [
- {
- source: "/api/:path*",
- destination: `${apiUrl}/api/:path*`,
- },
- {
- source: "/health",
- destination: `${apiUrl}/health`,
- },
- {
- source: "/metrics",
- destination: `${apiUrl}/metrics`,
- },
- ];
- },
};
export default nextConfig;
diff --git a/packages/web/src/middleware.ts b/packages/web/src/middleware.ts
new file mode 100644
index 000000000..de63091d5
--- /dev/null
+++ b/packages/web/src/middleware.ts
@@ -0,0 +1,22 @@
+import { NextResponse } from 'next/server';
+import type { NextRequest } from 'next/server';
+
+export function middleware(request: NextRequest) {
+ const apiUrl = process.env.REPOWISE_API_URL || "http://localhost:7337";
+
+ // Construct the destination URL using the runtime API base URL
+ const destination = new URL(
+ request.nextUrl.pathname + request.nextUrl.search,
+ apiUrl
+ );
+
+ return NextResponse.rewrite(destination);
+}
+
+export const config = {
+ matcher: [
+ '/api/:path*',
+ '/health',
+ '/metrics'
+ ],
+};