File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99/**
1010 * 浏览器端 API 基础地址(NEXT_PUBLIC_*,构建时注入,面向用户浏览器)
11- * Docker 部署时应设置为宿主机可访问的地址,如 http://localhost:8000/api/v1
11+ * - 开发:默认 http://localhost:8000/api/v1(也可用 .env.local 覆盖)
12+ * - 生产构建:若环境变量未设或为空字符串,默认 `/api/v1`(同域 + 反代 /api → 后端)
13+ * 避免出现空 baseURL 时 axios 把 `/setup/status` 发到页面源站根路径导致 404。
1214 */
13- export const API_BASE =
14- process . env . NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8000/api/v1"
15+ export const API_BASE = ( ( ) => {
16+ const raw = process . env . NEXT_PUBLIC_API_BASE_URL ?. trim ( ) ?? ""
17+ if ( raw !== "" ) return raw
18+ return process . env . NODE_ENV === "production" ? "/api/v1" : "http://localhost:8000/api/v1"
19+ } ) ( )
1520
1621/**
1722 * 服务端 SSR 内部 API 地址(运行时读取,非 NEXT_PUBLIC_*)
Original file line number Diff line number Diff line change @@ -128,6 +128,8 @@ services:
128128 image : ghcr.io/linmoqc/lyranote/web:main
129129 restart : unless-stopped
130130 environment :
131+ # 仅同域反代时镜像内已是 /api/v1 即可。注意:NEXT_PUBLIC_* 在 next build 时写入产物;
132+ # 若 API 独立域名,须用该 URL 重新构建 web 镜像(非仅改此处)。
131133 NEXT_PUBLIC_API_BASE_URL : /api/v1
132134 INTERNAL_API_BASE_URL : http://api:8000/api/v1
133135 NODE_ENV : production
You can’t perform that action at this time.
0 commit comments