diff --git a/src/services/aiService.ts b/src/services/aiService.ts index 8c4ab8a..08baf89 100644 --- a/src/services/aiService.ts +++ b/src/services/aiService.ts @@ -4,7 +4,7 @@ * Validates: Requirements 12.1-12.6 */ -import api from './api'; +import api, { API_BASE_URL } from './api'; import type { ApiResponse, AIChatResponse, @@ -108,7 +108,7 @@ export async function streamChatMessage( const token = localStorage.getItem('token'); // Assuming auth token is stored here // Use fetch directly for streaming support - const response = await fetch(`${import.meta.env.VITE_API_BASE_URL}/ai/chat/stream`, { + const response = await fetch(`${API_BASE_URL}/ai/chat/stream`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/services/api.ts b/src/services/api.ts index 3a42bd9..06e7926 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -7,7 +7,8 @@ // 优先使用环境变量配置 // 开发环境 (.env.development): http://localhost:2612/api/v1 // 生产环境 (.env.production): /api/v1 -const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || +// 生产环境 (.env.production): /api/v1 +export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ((window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') ? 'http://localhost:2612/api/v1' : '/api/v1');