feat: 添加 API 服务,支持环境配置、认证管理和自动刷新令牌。
This commit is contained in:
1
.env.development
Normal file
1
.env.development
Normal file
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=http://localhost:2612/api/v1
|
||||
1
.env.production
Normal file
1
.env.production
Normal file
@@ -0,0 +1 @@
|
||||
VITE_API_BASE_URL=/api/v1
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user