From 83b4c7bcad4a13eed8a180ad9d189eebb9347b04 Mon Sep 17 00:00:00 2001 From: BigUncle Date: Fri, 1 May 2026 20:50:12 +0800 Subject: [PATCH 1/2] fix: add missing Vercel rewrite rules for admin API routes /admin/chat-history, /admin/proxies, /admin/dev/raw-samples, and /admin/dev/captures were falling through to the SPA fallback (/admin/index.html), causing "Unexpected token '<'" JSON parse errors on the frontend. --- vercel.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vercel.json b/vercel.json index 600a53c..5cebd5d 100644 --- a/vercel.json +++ b/vercel.json @@ -81,6 +81,22 @@ "source": "/admin/version", "destination": "/api/index" }, + { + "source": "/admin/chat-history(.*)", + "destination": "/api/index" + }, + { + "source": "/admin/proxies(.*)", + "destination": "/api/index" + }, + { + "source": "/admin/dev/raw-samples/(.*)", + "destination": "/api/index" + }, + { + "source": "/admin/dev/captures(.*)", + "destination": "/api/index" + }, { "source": "/admin", "destination": "/admin/index.html" From 3430322e8179bc5a3c290b535546fa1ecb269813 Mon Sep 17 00:00:00 2001 From: BigUncle Date: Fri, 1 May 2026 21:17:52 +0800 Subject: [PATCH 2/2] docs: add Vercel chat history read-only filesystem troubleshooting --- docs/DEPLOY.en.md | 17 +++++++++++++++++ docs/DEPLOY.md | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/docs/DEPLOY.en.md b/docs/DEPLOY.en.md index a7716a3..b2ed75e 100644 --- a/docs/DEPLOY.en.md +++ b/docs/DEPLOY.en.md @@ -271,6 +271,7 @@ VERCEL_TEAM_ID=team_xxxxxxxxxxxx # optional for personal accounts | `VERCEL_TOKEN` | Vercel sync token | — | | `VERCEL_PROJECT_ID` | Vercel project ID | — | | `VERCEL_TEAM_ID` | Vercel team ID | — | +| `DS2API_CHAT_HISTORY_PATH` | Chat history storage path (must be set to `/tmp/chat_history.json` on Vercel, otherwise unavailable due to read-only filesystem) | `data/chat_history.json` | | `DS2API_VERCEL_PROTECTION_BYPASS` | Deployment protection bypass for internal Node→Go calls | — | ### 3.4 Vercel Architecture @@ -360,6 +361,22 @@ If API responses return Vercel HTML `Authentication Required`: - **Option B**: Add `x-vercel-protection-bypass` header to requests - **Option C**: Set `VERCEL_AUTOMATION_BYPASS_SECRET` (or `DS2API_VERCEL_PROTECTION_BYPASS`) for internal Node→Go calls +#### Chat History Unavailable (read-only file system) + +```text +create chat history dir: mkdir /var/task/data: read-only file system +``` + +**Cause**: Vercel Serverless functions have a read-only filesystem (`/var/task`). Chat history fails because it cannot create directories there. + +**Fix**: Add the following in Vercel Project Settings → Environment Variables: + +```text +DS2API_CHAT_HISTORY_PATH=/tmp/chat_history.json +``` + +`/tmp` is the only writable directory in Vercel Serverless. Data is ephemeral (not persisted across cold starts), but the feature works within a single instance lifetime. + ### 3.6 Build Artifacts Not Committed - `static/admin` directory is not in Git diff --git a/docs/DEPLOY.md b/docs/DEPLOY.md index 3ff20ed..4a1b75f 100644 --- a/docs/DEPLOY.md +++ b/docs/DEPLOY.md @@ -271,6 +271,7 @@ VERCEL_TEAM_ID=team_xxxxxxxxxxxx # 个人账号可留空 | `VERCEL_TOKEN` | Vercel 同步 token | — | | `VERCEL_PROJECT_ID` | Vercel 项目 ID | — | | `VERCEL_TEAM_ID` | Vercel 团队 ID | — | +| `DS2API_CHAT_HISTORY_PATH` | Chat history 存储路径(Vercel 上必须设为 `/tmp/chat_history.json`,否则因文件系统只读而不可用) | `data/chat_history.json` | | `DS2API_VERCEL_PROTECTION_BYPASS` | 部署保护绕过密钥(内部 Node→Go 调用) | — | ### 3.3 运行时行为配置(通过 Admin API 设置) @@ -370,6 +371,22 @@ No Output Directory named "public" found after the Build completed. - **方案 B**:请求中添加 `x-vercel-protection-bypass` 头 - **方案 C**:设置 `VERCEL_AUTOMATION_BYPASS_SECRET`(或 `DS2API_VERCEL_PROTECTION_BYPASS`),仅影响内部 Node→Go 调用 +#### Chat History 不可用(read-only file system) + +```text +create chat history dir: mkdir /var/task/data: read-only file system +``` + +**原因**:Vercel Serverless 函数的文件系统(`/var/task`)为只读,chat history 尝试在该路径下创建目录失败。 + +**解决**:在 Vercel Project Settings → Environment Variables 中添加: + +```text +DS2API_CHAT_HISTORY_PATH=/tmp/chat_history.json +``` + +`/tmp` 是 Vercel Serverless 环境中唯一可写的目录。数据在函数冷启动之间不会持久化(ephemeral),但在单个实例生命周期内功能正常。 + ### 3.6 仓库不提交构建产物 - `static/admin` 目录不在 Git 中