feat: 添加 API 服务,支持环境配置、认证管理和自动刷新令牌。

This commit is contained in:
2026-01-28 12:51:31 +08:00
parent 4bb0c35de4
commit c7f1571a73
3 changed files with 9 additions and 4 deletions

1
.env.development Normal file
View File

@@ -0,0 +1 @@
VITE_API_BASE_URL=http://localhost:2612/api/v1

1
.env.production Normal file
View File

@@ -0,0 +1 @@
VITE_API_BASE_URL=/api/v1

View File

@@ -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';