From 9d1f52d95be36f0008ab7a6e7e388a4b014a6184 Mon Sep 17 00:00:00 2001 From: Wang Zhuoxuan Date: Sat, 18 Apr 2026 04:13:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20health=20=E8=B7=AF=E7=94=B1=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E4=BF=AE=E6=AD=A3=E4=B8=BA=20/health?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit healthRoutes 注册时无 /v1 前缀,实际路径是 /health 而非 /v1/health。 将 auth 中间件白名单从 /v1/health 改为 /health,并同步修正所有 HEALTHCHECK 和 CI health check 路径。 --- .gitea/workflows/deploy.yml | 4 ++-- Dockerfile | 2 +- docker-compose.prod.yml | 4 ++-- src/middleware/auth.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index de9e99a..f4edbb6 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -69,7 +69,7 @@ jobs: run: | sleep 10 for i in {1..5}; do - if bun -e "try{const r=await fetch('http://localhost:3001/v1/health');process.exit(r.ok?0:1)}catch{process.exit(1)}"; then + if bun -e "try{const r=await fetch('http://localhost:3001/health');process.exit(r.ok?0:1)}catch{process.exit(1)}"; then echo "Test environment is healthy!" exit 0 fi @@ -106,7 +106,7 @@ jobs: sleep 15 for i in {1..5}; do echo "Health check attempt $i..." - bun -e "try{const r=await fetch('http://localhost:3000/v1/health');console.log('status:',r.status,'ok:',r.ok);process.exit(r.ok?0:1)}catch(e){console.error('ERROR:',e.message);process.exit(1)}" + bun -e "try{const r=await fetch('http://localhost:3000/health');console.log('status:',r.status,'ok:',r.ok);process.exit(r.ok?0:1)}catch(e){console.error('ERROR:',e.message);process.exit(1)}" if [ $? -eq 0 ]; then echo "Production deployment successful!" exit 0 diff --git a/Dockerfile b/Dockerfile index 8ebea1b..1aeebdd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,7 +44,7 @@ EXPOSE 3000 # 健康检查 HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ - CMD curl -f http://localhost:3000/v1/health || exit 1 + CMD curl -f http://localhost:3000/health || exit 1 # 启动应用 CMD ["node", "dist/index.js"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 6e220d7..3457ce7 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -22,7 +22,7 @@ services: network_mode: host env_file: .env.prod healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000/v1/health"] + test: ["CMD", "curl", "-f", "http://localhost:3000/health"] interval: 30s timeout: 10s retries: 3 @@ -48,7 +48,7 @@ services: network_mode: host env_file: .env.test healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3001/v1/health"] + test: ["CMD", "curl", "-f", "http://localhost:3001/health"] interval: 30s timeout: 10s retries: 3 diff --git a/src/middleware/auth.ts b/src/middleware/auth.ts index cc5dad8..48ccb70 100644 --- a/src/middleware/auth.ts +++ b/src/middleware/auth.ts @@ -13,11 +13,11 @@ declare module '@fastify/jwt' { async function authMiddleware(app: FastifyInstance): Promise { app.addHook('onRequest', async (request) => { const publicPaths = [ + '/health', '/v1/auth/huawei', '/v1/auth/guest', '/v1/auth/phone', '/v1/auth/refresh', - '/v1/health', ]; if (publicPaths.some((p) => request.url.startsWith(p))) {