diff --git a/Dockerfile b/Dockerfile index 7abc190..b0efb14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ ENV OTA_PUBLIC_BASE=http://bh.vps.honor3.com:3002 # 健康检查 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD wget -qO- http://127.0.0.1:3002/api/health || exit 1 + CMD wget -qO- http://127.0.0.1:3002/healthz || exit 1 EXPOSE 3002 diff --git a/README.md b/README.md index 8283c35..99e029b 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,8 @@ bash scripts/build-apk.sh debug # 或 release | `GET /api/ota/check/:seq` | 有新包 → 200 + manifest;无 → 204 | | `GET /api/ota/bundle/:file` | 下载 tar.gz 升级包 (流式) | | `GET /api/ota/manifest-web` | Web 简化版 manifest | -| `GET /api/health` | 健康检查 | +| `GET /healthz` | 容器活性检查 (Dockerfile HEALTHCHECK 使用) | +| `GET /api/health` | 健康检查 (兼容旧引用) | 数据源: 环境变量 `OTA_PACKAGE_DIR`(默认 `ota-package/`)下的 `latest.json` + `wardrobe-ota.tar.gz`。 `PORT` 默认 `3002`(与 iboard 的 3001 同机共存)。可选 `OTA_PUBLIC_BASE` 让客户端直连 R2 下载 bundle。 diff --git a/server/index.js b/server/index.js index 11005d8..b732706 100644 --- a/server/index.js +++ b/server/index.js @@ -14,7 +14,8 @@ const app = express() app.use(cors()) app.use(express.json()) -// 健康检查 +// 健康检查 (容器活性探针统一用 /healthz, 保留 /api/health 兼容旧引用) +app.get('/healthz', (_req, res) => res.json({ ok: true, ts: Date.now() })) app.get('/api/health', (_req, res) => res.json({ ok: true, ts: Date.now() })) // OTA 接口公开 (检查/下载更新不需要登录), 必须挂载在最前面 @@ -25,9 +26,12 @@ if (HAS_DIST) { app.use(express.static(DIST_DIR, { index: false, maxAge: '1h', etag: true })) // SPA fallback: 非 /api/* 的请求一律返回 index.html, 由前端路由处理 + // 必须 no-cache: 否则浏览器/代理缓存旧 index.html, 引用的仍是旧哈希资源, + // 与部署的 dist 产生"版本不一致"(web 用户刷新也拿不到新页面) app.get(/^\/(?!api\/).*/, (_req, res, next) => { const indexHtml = path.join(DIST_DIR, 'index.html') if (!fs.existsSync(indexHtml)) return next() + res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate') res.sendFile(indexHtml) }) } diff --git a/src/pages/Landing.tsx b/src/pages/Landing.tsx index 7846f60..a6fb129 100644 --- a/src/pages/Landing.tsx +++ b/src/pages/Landing.tsx @@ -1,7 +1,6 @@ -import React, { useEffect, useState } from "react"; +import React from "react"; import { QRCodeSVG } from "qrcode.react"; import { APP_VERSION, BUILD_ID } from "../version"; -import { checkOtaUpdate, reloadApp } from "../api/ota"; // R2 公共桶中的 APK 产物 (由 android-build.yml 上传, 固定覆盖式) const APK_URL = "https://pub-98ee77ce79984c2cad0dc1c300901158.r2.dev/data/android/wardrobe.apk"; @@ -47,36 +46,6 @@ function DownloadSection() { ); } -function WebUpdateBanner() { - const [update, setUpdate] = useState(false); - const [note, setNote] = useState(""); - - useEffect(() => { - checkOtaUpdate().then((r) => { - if (r.available && r.info) { - setUpdate(true); - setNote(r.info.notes || ""); - } - }); - }, []); - - if (!update) return null; - return ( -
有新版本可用{note ? `: ${note}` : ""}
-请刷新页面获取最新体验
-