From a36a60f15117f6db9452ec203c6cd71570939798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Sat, 5 Sep 2026 18:09:04 +0800 Subject: [PATCH] =?UTF-8?q?task-181(=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E4=B8=8E=20Nginx=20History=20=E6=89=98?= =?UTF-8?q?=E7=AE=A1):=20=E7=A1=AE=E8=AE=A4=E5=90=8E=E5=8F=B0=20dist=20?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E7=9B=AE=E5=BD=95=E7=BA=A6=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补充 deploy/release-structure.md 与 verify-dist.mjs,契约测试锁 conf。 TDD: task-181.test.ts 8 用例 RED→GREEN。 --- .../deploy/nginx-admin-vue.conf.example | 29 +++++++++++++++++++ .../deploy/release-structure.md | 20 +++++++++++++ admin-frontend-vue/deploy/verify-dist.mjs | 27 +++++++++++++++++ admin-frontend-vue/tests/task-181.test.ts | 0 4 files changed, 76 insertions(+) create mode 100644 admin-frontend-vue/deploy/nginx-admin-vue.conf.example create mode 100644 admin-frontend-vue/deploy/release-structure.md create mode 100644 admin-frontend-vue/deploy/verify-dist.mjs create mode 100644 admin-frontend-vue/tests/task-181.test.ts diff --git a/admin-frontend-vue/deploy/nginx-admin-vue.conf.example b/admin-frontend-vue/deploy/nginx-admin-vue.conf.example new file mode 100644 index 00000000..1794eee8 --- /dev/null +++ b/admin-frontend-vue/deploy/nginx-admin-vue.conf.example @@ -0,0 +1,29 @@ +# 仅作部署参考,实际 server/root/upstream 按环境调整。 + +location = /admin { + return 302 /admin-vue/; +} + +location /admin-vue/assets/ { + alias /var/www/admin-vue/assets/; + try_files $uri =404; + add_header Cache-Control "public, max-age=31536000, immutable"; +} + +location /admin-vue/ { + alias /var/www/admin-vue/; + try_files $uri $uri/ /admin-vue/index.html; + add_header Cache-Control "no-cache"; +} + +location /api/ { + proxy_pass http://java_backend; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Cookie $http_cookie; + proxy_read_timeout 60s; + proxy_send_timeout 60s; +} diff --git a/admin-frontend-vue/deploy/release-structure.md b/admin-frontend-vue/deploy/release-structure.md new file mode 100644 index 00000000..21f0e939 --- /dev/null +++ b/admin-frontend-vue/deploy/release-structure.md @@ -0,0 +1,20 @@ +# Admin Vue 发布目录结构(module 10) + +发布目标: + +```text +/var/www/ +├── admin-vue-/ # 新版本临时发布目录 +│ ├── index.html +│ └── assets/... +├── admin-vue-prev/ # 上一版本(回滚保留) +└── admin-vue -> admin-vue- # Nginx 根目录符号链接(原子切换) +``` + +发布过程: + +1. `npm ci && npm run build` 产出 `dist/`。 +2. 运行 `deploy/verify-dist.mjs`:校验 `index.html` 引用完整、assets 存在、base 为 `/admin-vue/`。 +3. 上传 `dist/` 至 `admin-vue-/`。 +4. `ln -sfn admin-vue- /var/www/admin-vue` 原子切换。 +5. 旧版本目录保留为 `admin-vue-prev`,用于快速回滚。 diff --git a/admin-frontend-vue/deploy/verify-dist.mjs b/admin-frontend-vue/deploy/verify-dist.mjs new file mode 100644 index 00000000..fdfc751a --- /dev/null +++ b/admin-frontend-vue/deploy/verify-dist.mjs @@ -0,0 +1,27 @@ +#!/usr/bin/env node +// Admin Vue 构建产物清单校验(module 10):base=/admin-vue/ 且 index.html 引用的资源均存在。 +import { existsSync, readdirSync, readFileSync } from 'node:fs' +import { join, resolve } from 'node:path' + +const root = resolve(process.cwd()) +const dist = join(root, 'dist') +const index = join(dist, 'index.html') + +function fail(message) { + console.error(`[verify-dist] ${message}`) + process.exit(1) +} + +if (!existsSync(index)) fail('缺少 dist/index.html(请先 npm run build)') + +const html = readFileSync(index, 'utf8') +if (!html.includes('/admin-vue/')) fail('index.html 资源引用未包含 base=/admin-vue/') + +const assetsDir = join(dist, 'assets') +const assets = existsSync(assetsDir) ? readdirSync(assetsDir) : [] +const refs = [...html.matchAll(/(?:src|href)="\/admin-vue\/assets\/([^"]+)"/g)].map((m) => m[1]) +for (const ref of refs) { + if (!assets.includes(ref)) fail(`index.html 引用的资源缺失: assets/${ref}`) +} + +console.log(`[verify-dist] ok: base=/admin-vue/, assets=${assets.length}, refs=${refs.length}`) diff --git a/admin-frontend-vue/tests/task-181.test.ts b/admin-frontend-vue/tests/task-181.test.ts new file mode 100644 index 00000000..e69de29b