diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..9ffe781 --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +VITE_API_BASE_URL=http://localhost:2612/api/v1 diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..2bf124d --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_API_BASE_URL=/api/v1 diff --git a/src/services/api.ts b/src/services/api.ts index a25b0ef..3a42bd9 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -4,10 +4,13 @@ * Validates: Requirements 12.3, 12.4 */ -const isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'; -const API_BASE_URL = isLocal - ? (import.meta.env.VITE_API_BASE_URL || 'http://localhost:2612/api/v1') - : '/api/v1'; +// 优先使用环境变量配置 +// 开发环境 (.env.development): http://localhost:2612/api/v1 +// 生产环境 (.env.production): /api/v1 +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'); // Token storage keys const ACCESS_TOKEN_KEY = 'access_token';