fix(admin-web): fix trading-service proxy routing for Kong gateway
- Add production/development environment detection - Production: route through Kong gateway at /api/v2/trading/* - Development: direct connection to trading-service at localhost:3022 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
8018fa5110
commit
2da02e0823
|
|
@ -3,25 +3,47 @@ const nextConfig = {
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
output: 'standalone',
|
output: 'standalone',
|
||||||
async rewrites() {
|
async rewrites() {
|
||||||
// NEXT_PUBLIC_API_URL 应该是后端服务的基础 URL,如 http://mining-admin-service:3023
|
// 获取 API 基础 URL(Kong 网关地址)
|
||||||
// 前端请求 /api/xxx 会被转发到 {API_URL}/api/v2/xxx
|
// 生产环境: https://rwaapi.szaiai.com
|
||||||
const apiBaseUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3023';
|
// 开发环境: http://localhost:3023 (mining-admin-service)
|
||||||
const tradingServiceUrl = process.env.TRADING_SERVICE_URL || 'http://localhost:3020';
|
const apiGatewayUrl = process.env.API_GATEWAY_URL || 'https://rwaapi.szaiai.com';
|
||||||
// 移除末尾可能存在的 /api/v2 避免重复
|
const miningAdminUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3023';
|
||||||
const cleanUrl = apiBaseUrl.replace(/\/api\/v2\/?$/, '');
|
const tradingServiceUrl = process.env.TRADING_SERVICE_URL || 'http://localhost:3022';
|
||||||
const cleanTradingUrl = tradingServiceUrl.replace(/\/api\/v2\/?$/, '');
|
|
||||||
return [
|
// 检查是否是生产环境(使用 Kong 网关)
|
||||||
// trading-service 路由
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
{
|
|
||||||
source: '/api/trading/:path*',
|
// 移除末尾可能存在的路径避免重复
|
||||||
destination: `${cleanTradingUrl}/api/v2/:path*`,
|
const cleanMiningUrl = miningAdminUrl.replace(/\/api\/v2.*$/, '');
|
||||||
},
|
const cleanTradingUrl = tradingServiceUrl.replace(/\/api\/v2.*$/, '');
|
||||||
// mining-admin-service 路由 (默认)
|
|
||||||
{
|
if (isProduction) {
|
||||||
source: '/api/:path*',
|
// 生产环境:通过 Kong 网关
|
||||||
destination: `${cleanUrl}/api/v2/:path*`,
|
// /api/trading/* -> Kong -> trading-service
|
||||||
},
|
// /api/* -> Kong -> mining-admin-service
|
||||||
];
|
return [
|
||||||
|
{
|
||||||
|
source: '/api/trading/:path*',
|
||||||
|
destination: `${apiGatewayUrl}/api/v2/trading/:path*`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/api/:path*',
|
||||||
|
destination: `${apiGatewayUrl}/api/v2/mining-admin/:path*`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// 开发环境:直连各服务
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/api/trading/:path*',
|
||||||
|
destination: `${cleanTradingUrl}/api/v2/:path*`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/api/:path*',
|
||||||
|
destination: `${cleanMiningUrl}/api/v2/:path*`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue