feat: 配置简化为同源相对路径,统一 /api/ 路由约定

配合 zTools2 路由统一到 /api/,简化环境感知配置:
- app.config.js:去掉 BASE_URL 的 dev/prod 分支,iframe 与探针一律用同源相对路径
  (/api/pdf、/api/health、/api/wb-page/{id}),默认空 baseUrl;保留 VITE_API_BASE 覆盖。
  这样无论 dev(vite proxy)还是任意部署环境(反代),同源相对路径都自动指向当前环境 zTools2,
  不再误打到 f.zikai.wang 等其它环境域名。
- vite.config.js:dev proxy 从 /api /pdf /health /static /upload /files /wb /ws 多条
  简化为单条 /api(含 ws:true,覆盖 /api/ws WebSocket)。
- deploy.sh:Apache vhost 从多条 ProxyPass 简化为单条 /api/,a2enmod 增加 proxy_wstunnel。
- docs/deployment.md:更新拓扑/模式说明,新增路由约定(所有入口在 /api/ 下,反代只需一条规则)。
- 同步更新 zPDF_package 子模块指针(其 vite proxy 亦简化为单条 /api)。
This commit is contained in:
2026-07-27 15:44:49 +08:00
parent 39f3056099
commit 304ebc9448
5 changed files with 43 additions and 85 deletions

View File

@@ -2,41 +2,38 @@
// 模块按需 import { appConfig } 使用,改 URL 只改这里即可(需重新 build
// 每个服务项都带默认值,避免缺失字段导致渲染崩溃。
//
// 环境感知(测试环境指向测试环境,生产环境指向生产环境):
// - 开发服务器vite dev / MODE=developmentbaseUrl 为空串(同源),
// 经 vite.config.js 的 server.proxy /api /pdf /health /static 等同源代理到
// 本地 zTools2127.0.0.1:6867使 iframe 与 fetch 都命中本地服务。
// - 生产构建vite build / MODE=productionbaseUrl 指向线上 f.zikai.wang同源
// - 可用 VITE_API_BASE 覆盖(如自定义测试环境域名,需含协议)
// 路由约定zTools2 所有入口(页面/静态/探针/WS/API统一挂在 /api/ 下,
// iframe 与 fetch 一律用**同源相对路径**/api/pdf、/api/health 等)。
// 无论是 vite devserver.proxy 转发 /api 到本地 zTools2、还是任意部署环境
// Apache/Nginx 反代 /api 到当前环境的 zTools2同源相对路径都自动指向
// **当前环境**的服务,无需区分 dev/prod也不会误打到其它环境域名
// 罕见需要时可设 VITE_API_BASE(含协议与域名)显式覆盖为绝对地址
// 生产构建用线上地址(同源);开发用空串(同源,经 vite proxy 转发到本地 zTools2
// 允许 VITE_API_BASE 显式覆盖(如指向独立测试环境域名)
const BASE_URL =
import.meta.env.VITE_API_BASE ||
(import.meta.env.PROD ? 'https://f.zikai.wang' : '')
// 默认空串 = 同源相对路径VITE_API_BASE 可覆盖为绝对地址(如指向独立测试环境域名)
const BASE_URL = import.meta.env.VITE_API_BASE || ''
export const appConfig = {
// 共享记事本(白板)服务
whiteboard: {
// 服务根地址(含协议与域名)
// 服务根地址(含协议与域名);默认空串 = 同源相对路径
baseUrl: BASE_URL,
// 存活探针路径;周期探测,挂掉则隐藏页签并卸载组件
healthPath: '/health',
healthPath: '/api/health',
// 记事本页面路径生成器
pagePath: (boardId) => `/wb/${encodeURIComponent(boardId)}`,
pagePath: (boardId) => `/api/wb-page/${encodeURIComponent(boardId)}`,
// 默认打开的记事本 id
defaultBoardId: 'share',
// 探测超时(毫秒)
healthTimeoutMs: 4000
},
// PDF 转换服务zTools2 托管的 /pdf 页面iframe 同源嵌入)
// PDF 转换服务zTools2 托管的 /api/pdf 页面iframe 同源嵌入)
pdf: {
// 服务根地址(含协议与域名)
// 服务根地址(含协议与域名);默认空串 = 同源相对路径
baseUrl: BASE_URL,
// 存活探针路径;周期探测,挂掉则隐藏页签并卸载组件
healthPath: '/health',
healthPath: '/api/health',
// PDF 转换页面路径
pagePath: '/pdf',
pagePath: '/api/pdf',
// 探测超时(毫秒)
healthTimeoutMs: 4000
}
@@ -45,7 +42,7 @@ export const appConfig = {
/**
* 取某服务的存活探针 URL。
* @param {keyof typeof appConfig} service 配置中的服务名
* @returns {string} 完整探针 URL https://f.zikai.wang/health
* @returns {string} 完整探针 URL同源相对 /api/health 或绝对地址
*/
export function healthUrl(service) {
const cfg = appConfig[service]