From ff4671093db4c835df6a4653b872d03898a656ac Mon Sep 17 00:00:00 2001 From: "G.Wood-Sun" Date: Thu, 22 May 2025 15:10:27 +0800 Subject: [PATCH] chore: add next rewrite config for dev api --- web/.env.example | 2 ++ web/next.config.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/web/.env.example b/web/.env.example index 51631c2437..7923053f2c 100644 --- a/web/.env.example +++ b/web/.env.example @@ -56,3 +56,5 @@ NEXT_PUBLIC_ENABLE_WEBSITE_JINAREADER=true NEXT_PUBLIC_ENABLE_WEBSITE_FIRECRAWL=true NEXT_PUBLIC_ENABLE_WEBSITE_WATERCRAWL=true +# development api service base +NEXT_DEV_API_PROXY_BASE_URL=http://127.0.0.1:5001 diff --git a/web/next.config.js b/web/next.config.js index 9ce1b35644..07860e9b52 100644 --- a/web/next.config.js +++ b/web/next.config.js @@ -63,6 +63,23 @@ const nextConfig = { }, ] }, + async rewrites() { + // development service rewrite + if (process.env.NEXT_PUBLIC_DEPLOY_ENV !== 'production' && process.env.NEXT_DEV_API_PROXY_BASE_URL) { + const apiBase = process.env.NEXT_DEV_API_PROXY_BASE_URL + return [ + { + source: '/api/:path*', // match /api/* + destination: `${apiBase}/api/:path*`, // rewrite + }, + { + source: '/console/api/:path*', // match /console/api/* + destination: `${apiBase}/console/api/:path*`, // rewrite + }, + ] + } + return [] + }, output: 'standalone', }