From d668465734b5471ea5271a928a3b459c0a181403 Mon Sep 17 00:00:00 2001 From: CJACK Date: Mon, 16 Feb 2026 20:50:32 +0800 Subject: [PATCH] fix(vercel): route admin static assets before api fallback --- DEPLOY.en.md | 1 + DEPLOY.md | 1 + vercel.json | 57 +++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/DEPLOY.en.md b/DEPLOY.en.md index 8ac9927..42f3b48 100644 --- a/DEPLOY.en.md +++ b/DEPLOY.en.md @@ -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: diff --git a/DEPLOY.md b/DEPLOY.md index 75b3d90..78f92ea 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -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` 至少配置环境变量: diff --git a/vercel.json b/vercel.json index cef374e..db2bc6a 100644 --- a/vercel.json +++ b/vercel.json @@ -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"