fix(admin-web): use dedicated trading client with correct base URL
Trading API was incorrectly routed through mining-admin baseURL in production, causing 404 errors. Created independent tradingClient with /api/trading baseURL to properly route requests through Next.js rewrites to Kong -> trading-service. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
52a5ae64c0
commit
7b3c222b24
|
|
@ -1,4 +1,41 @@
|
||||||
import { apiClient } from '@/lib/api/client';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
// Trading API 需要独立的 baseURL,因为它走不同的路由
|
||||||
|
// 生产环境: 通过 Next.js rewrite /api/trading/* -> Kong -> trading-service
|
||||||
|
// 开发环境: 通过 Next.js rewrite /api/trading/* -> trading-service
|
||||||
|
const tradingBaseURL = '/api/trading';
|
||||||
|
|
||||||
|
const tradingClient = axios.create({
|
||||||
|
baseURL: tradingBaseURL,
|
||||||
|
timeout: 30000,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
tradingClient.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
const token = typeof window !== 'undefined' ? localStorage.getItem('admin_token') : null;
|
||||||
|
if (token) {
|
||||||
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => Promise.reject(error)
|
||||||
|
);
|
||||||
|
|
||||||
|
tradingClient.interceptors.response.use(
|
||||||
|
(response) => response,
|
||||||
|
(error) => {
|
||||||
|
if (error.response?.status === 401) {
|
||||||
|
localStorage.removeItem('admin_token');
|
||||||
|
if (typeof window !== 'undefined' && !window.location.pathname.includes('/login')) {
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export interface TradingStatus {
|
export interface TradingStatus {
|
||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
|
|
@ -41,26 +78,26 @@ export interface BurnRecordsResponse {
|
||||||
export const tradingApi = {
|
export const tradingApi = {
|
||||||
// 获取交易系统状态
|
// 获取交易系统状态
|
||||||
getTradingStatus: async (): Promise<TradingStatus> => {
|
getTradingStatus: async (): Promise<TradingStatus> => {
|
||||||
const response = await apiClient.get('/trading/admin/trading/status');
|
const response = await tradingClient.get('/admin/trading/status');
|
||||||
// 后端返回 { success, data, timestamp }
|
// 后端返回 { success, data, timestamp }
|
||||||
return response.data.data || response.data;
|
return response.data.data || response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 激活交易系统
|
// 激活交易系统
|
||||||
activateTrading: async (): Promise<{ success: boolean; message: string; activatedAt?: string }> => {
|
activateTrading: async (): Promise<{ success: boolean; message: string; activatedAt?: string }> => {
|
||||||
const response = await apiClient.post('/trading/admin/trading/activate');
|
const response = await tradingClient.post('/admin/trading/activate');
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 关闭交易系统
|
// 关闭交易系统
|
||||||
deactivateTrading: async (): Promise<{ success: boolean; message: string }> => {
|
deactivateTrading: async (): Promise<{ success: boolean; message: string }> => {
|
||||||
const response = await apiClient.post('/trading/admin/trading/deactivate');
|
const response = await tradingClient.post('/admin/trading/deactivate');
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取销毁状态
|
// 获取销毁状态
|
||||||
getBurnStatus: async (): Promise<BurnStatus> => {
|
getBurnStatus: async (): Promise<BurnStatus> => {
|
||||||
const response = await apiClient.get('/trading/burn/status');
|
const response = await tradingClient.get('/burn/status');
|
||||||
// 后端返回 { success, data, timestamp }
|
// 后端返回 { success, data, timestamp }
|
||||||
return response.data.data || response.data;
|
return response.data.data || response.data;
|
||||||
},
|
},
|
||||||
|
|
@ -78,7 +115,7 @@ export const tradingApi = {
|
||||||
if (sourceType) {
|
if (sourceType) {
|
||||||
params.append('sourceType', sourceType);
|
params.append('sourceType', sourceType);
|
||||||
}
|
}
|
||||||
const response = await apiClient.get(`/trading/burn/records?${params.toString()}`);
|
const response = await tradingClient.get(`/burn/records?${params.toString()}`);
|
||||||
// 后端返回 { data: [...], total: number }
|
// 后端返回 { data: [...], total: number }
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
@ -95,7 +132,7 @@ export const tradingApi = {
|
||||||
burnTarget: string;
|
burnTarget: string;
|
||||||
burnProgress: string;
|
burnProgress: string;
|
||||||
}> => {
|
}> => {
|
||||||
const response = await apiClient.get('/trading/asset/market');
|
const response = await tradingClient.get('/asset/market');
|
||||||
// 后端返回 { success, data, timestamp }
|
// 后端返回 { success, data, timestamp }
|
||||||
return response.data.data;
|
return response.data.data;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue