This commit is contained in:
root
2026-06-07 12:48:17 +08:00
parent 9ee203c221
commit 283d65d1d1
46 changed files with 1205 additions and 2579 deletions

View File

@@ -1,9 +1,12 @@
export const API_BASE =
process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:8000";
export const API_BASE = (process.env.NEXT_PUBLIC_API_BASE_URL || "").replace(/\/$/, "");
export function apiUrl(path: string): string {
if (/^https?:\/\//i.test(path)) return path;
return `${API_BASE}${path.startsWith("/") ? path : `/${path}`}`;
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
if (API_BASE.endsWith("/api") && normalizedPath.startsWith("/api/")) {
return `${API_BASE}${normalizedPath.slice(4)}`;
}
return `${API_BASE}${normalizedPath}`;
}
export async function apiFetch<T>(