fix(vercel): route admin static assets before api fallback

This commit is contained in:
CJACK
2026-02-16 20:50:32 +08:00
parent 3cf207bcbb
commit d668465734
3 changed files with 54 additions and 5 deletions

View File

@@ -66,6 +66,7 @@ Notes:
- Serverless entry: `api/index.go`
- Rewrites and cache headers: `vercel.json`
- Build stage runs `npm ci --prefix webui && npm run build --prefix webui` automatically
- `vercel.json` routes `/admin/assets/*` and the `/admin` page to static output, while `/admin/*` APIs still go to `api/index`
Minimum environment variables:

View File

@@ -66,6 +66,7 @@ docker-compose up -d --build
- serverless 入口:`api/index.go`
- 路由与缓存头:`vercel.json`
- 构建阶段会自动执行 `npm ci --prefix webui && npm run build --prefix webui`
- `vercel.json` 已将 `/admin/assets/*``/admin` 页面走静态产物,`/admin/*` API 仍走 `api/index`
至少配置环境变量:

View File

@@ -2,12 +2,59 @@
"version": 2,
"buildCommand": "npm ci --prefix webui && npm run build --prefix webui",
"outputDirectory": "static/admin",
"functions": {
"api/index.go": {
"includeFiles": "static/admin/**"
}
},
"rewrites": [
{
"source": "/admin/login",
"destination": "/api/index"
},
{
"source": "/admin/verify",
"destination": "/api/index"
},
{
"source": "/admin/config",
"destination": "/api/index"
},
{
"source": "/admin/keys(.*)",
"destination": "/api/index"
},
{
"source": "/admin/accounts(.*)",
"destination": "/api/index"
},
{
"source": "/admin/queue/status",
"destination": "/api/index"
},
{
"source": "/admin/import",
"destination": "/api/index"
},
{
"source": "/admin/test",
"destination": "/api/index"
},
{
"source": "/admin/vercel/(.*)",
"destination": "/api/index"
},
{
"source": "/admin/export",
"destination": "/api/index"
},
{
"source": "/admin/assets/(.*)",
"destination": "/assets/$1"
},
{
"source": "/admin",
"destination": "/index.html"
},
{
"source": "/admin/(.*)",
"destination": "/index.html"
},
{
"source": "/(.*)",
"destination": "/api/index"