diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index ba6c152..77109c3 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -1,7 +1,9 @@ +// 服务端 SSR:使用内网地址直连后端 +// 客户端:使用空字符串(same-origin,通过 nginx 代理) const API_BASE = typeof window === "undefined" - ? process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080" - : process.env.NEXT_PUBLIC_API_URL || ""; + ? process.env.API_URL || "http://localhost:8080" + : ""; // 流式请求基础URL(运行时判断,不依赖编译时变量): // - 服务器端(SSR):直连后端 @@ -9,7 +11,7 @@ const API_BASE = // - 浏览器端生产环境:走同域nginx(已配proxy_buffering off) function getStreamBase() { if (typeof window === "undefined") { - return process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080"; + return process.env.API_URL || "http://localhost:8080"; } const host = window.location.hostname; if (host === "localhost" || host === "127.0.0.1") { @@ -234,7 +236,8 @@ export async function listPPTTasks() { } export function getPPTDownloadURL(taskId: string) { - const base = typeof window !== "undefined" ? process.env.NEXT_PUBLIC_API_URL || "" : ""; + // 客户端使用 same-origin,服务端不应调用此函数 + const base = typeof window !== "undefined" ? "" : ""; return `${base}/api/v1/ppt/tasks/${taskId}/download`; }