From 467d637ccc87dbca90fde60ba6d28462f422cfca Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 14 Jan 2026 04:37:32 -0800 Subject: [PATCH] fix(mining-admin-web): prevent duplicate /api/v2 in rewrite destination Clean NEXT_PUBLIC_API_URL to remove trailing /api/v2 if present, preventing paths like /api/v2/api/v2/configs/mining/status Co-Authored-By: Claude Opus 4.5 --- frontend/mining-admin-web/next.config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/mining-admin-web/next.config.js b/frontend/mining-admin-web/next.config.js index 3ccd409e..2dcb9a1b 100644 --- a/frontend/mining-admin-web/next.config.js +++ b/frontend/mining-admin-web/next.config.js @@ -3,10 +3,15 @@ const nextConfig = { reactStrictMode: true, output: 'standalone', async rewrites() { + // NEXT_PUBLIC_API_URL 应该是后端服务的基础 URL,如 http://mining-admin-service:3023 + // 前端请求 /api/xxx 会被转发到 {API_URL}/api/v2/xxx + const apiBaseUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3023'; + // 移除末尾可能存在的 /api/v2 避免重复 + const cleanUrl = apiBaseUrl.replace(/\/api\/v2\/?$/, ''); return [ { source: '/api/:path*', - destination: `${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3023'}/api/v2/:path*`, + destination: `${cleanUrl}/api/v2/:path*`, }, ]; },