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 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-14 04:37:32 -08:00
parent c9690b0d36
commit 467d637ccc
1 changed files with 6 additions and 1 deletions

View File

@ -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*`,
},
];
},