fix: 移除客户端对 NEXT_PUBLIC_API_URL 的依赖

- API_BASE 客户端使用空字符串(same-origin 通过 nginx)
- getStreamBase 服务端改用 API_URL
- getPPTDownloadURL 客户端使用 same-origin
- 彻底解决生产环境 CORS 错误
This commit is contained in:
selfrelease
2026-06-25 21:18:21 +08:00
parent 62dffb782a
commit 756849f99e
+7 -4
View File
@@ -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`;
}