fix: 移除所有硬编码的localhost:8080,使用相对路径
- 创建utils/config.ts集中管理API_BASE和文件URL - 删除.env文件(VITE_SERVER_API_URL=http://localhost:8080) - env.ts默认API前缀改为/api/v1匹配后端路由 - 替换16处硬编码的localhost:8080引用
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
export const API_BASE = import.meta.env.VITE_API_BASE_URL || '/api/v1'
|
||||
|
||||
export function getFileUrl(path: string): string {
|
||||
if (!path) return ''
|
||||
if (path.startsWith('http')) return path
|
||||
const base = import.meta.env.VITE_API_BASE || ''
|
||||
return `${base}${path}`
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import { z } from 'zod'
|
||||
|
||||
const EnvSchema = z.object({
|
||||
VITE_SERVER_API_URL: z.string().default(''),
|
||||
VITE_SERVER_API_PREFIX: z.string().default('/api'),
|
||||
VITE_SERVER_API_PREFIX: z.string().default('/api/v1'),
|
||||
VITE_SERVER_API_TIMEOUT: z.coerce.number().default(5000),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user