use middleware for runtime backend proxy
This commit is contained in:
11
web/middleware.js
Normal file
11
web/middleware.js
Normal file
@@ -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*',
|
||||||
|
}
|
||||||
@@ -2,14 +2,6 @@
|
|||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
output: 'standalone',
|
output: 'standalone',
|
||||||
reactCompiler: true,
|
reactCompiler: true,
|
||||||
async rewrites() {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
source: "/api/:path*",
|
|
||||||
destination: `${process.env.BACKEND_URL || "http://localhost:8080"}/api/:path*`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user