diff --git a/frontend/src/lib/http.ts b/frontend/src/lib/http.ts index 29217ff..251fdbc 100644 --- a/frontend/src/lib/http.ts +++ b/frontend/src/lib/http.ts @@ -17,6 +17,14 @@ export const UNAUTHORIZED_EVENT = 'profeto:unauthorized' const API_BASE = '/api/v1' const DEFAULT_TIMEOUT = 30_000 +/** 所有 API 路径统一走 /api/v1,避免浏览器直接请求 /matches 被 nginx 当 SPA 回退 */ +function build_url(path: string): string { + if (path.startsWith('http')) return path + if (path.startsWith(API_BASE)) return path + if (path.startsWith('/')) return `${API_BASE}${path}` + return `${API_BASE}/${path}` +} + export class ApiError extends Error { constructor( message: string, @@ -37,7 +45,7 @@ interface RequestOptions { } async function request(path: string, options: RequestOptions = {}): Promise { - const url = path.startsWith('http') ? path : path.startsWith('/') ? path : `${API_BASE}${path}` + const url = build_url(path) const { timeoutMs = DEFAULT_TIMEOUT, skipAuthHandling, signal } = options const controller = new AbortController()