Files
Mdeical_Sur_Report/docs/deployment.md
admin 750cf4129d Add audit log UI and backend API seeded E2E
- Add Auth Context route role guards so doctors cannot directly enter template management, user management, or audit logs.

- Add Audit Logs page, sidebar entry, frontend audit API client, and API client test.

- Add backend audit log query endpoint with super/admin visibility rules and query filtering.

- Extend PostgreSQL integration tests to cover audit log query permissions.

- Move Playwright E2E away from localStorage seed data to real backend API login and seed helpers.

- Add E2E coverage for route guards and audit log visibility.

- Run Playwright backend on port 3100 and proxy Vite API requests there to avoid local port conflicts.

- Make server:dev use the compiled NestJS server path, avoiding tsx parameter-property injection issues.

- Update README, AGENTS, feature, testing, security, deployment, progress, API, backendization, and auth/user module docs.
2026-05-02 02:04:56 +08:00

93 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 部署运行
## 本地开发
前端:
```bash
npm install
npm run dev
```
开发服务监听 `0.0.0.0:3001`
开发模式下 Vite 会把 `/api` 代理到 `VITE_API_PROXY_TARGET`,默认 `http://localhost:3000`
后端:
```bash
cp .env.example .env
npm run prisma:generate
npm run server:dev
```
本地直接运行 API 默认监听 `0.0.0.0:3000`,健康检查为:
```text
http://localhost:3000/api/health
```
如需连接真实 PostgreSQL
```bash
npm run prisma:migrate
npm run prisma:seed
```
## 质量检查
```bash
npm run lint
npm run test
npm run server:build
npm run build
```
当前 `lint` 实际执行 `tsc --noEmit`,用于 TypeScript 类型检查。
## 环境变量
复制示例文件:
```bash
cp .env.example .env.local
```
AI 和语音密钥由后端 Settings API 保存并由代理使用,前端不再注入 Gemini 旧环境变量。
后端新增变量:
- `API_PORT`API 监听端口。本地直接运行默认 `3000`Docker Compose 暴露到宿主机的默认端口是 `3002`
- `CORS_ORIGIN`:允许跨域携带 Cookie 的前端来源。
- `DATABASE_URL`PostgreSQL 连接串。Docker Compose 暴露到宿主机的默认端口是 `5433`,容器内部仍使用 `db:5432`
- `SESSION_SECRET`Session Cookie 签名密钥。
- `SESSION_COOKIE_SECURE`:是否只通过 HTTPS 发送 Session Cookie。本地 HTTP/Compose 默认 `false`,生产 HTTPS 应设为 `true`
- `FILE_STORAGE_DIR`后端文件目录。Docker Compose 默认 `/app/uploads`,并挂载到 `uploads_data` volume。
- `VITE_API_PROXY_TARGET`:前端开发服务器 `/api` 代理目标。直接运行后端用 `http://localhost:3000`;连接 Docker Compose API 用 `http://localhost:3002`
- `VITE_ENABLE_LOCAL_FALLBACK`:生产构建是否允许本地兼容回退。开发模式默认启用,生产默认关闭。
## Docker 部署
```bash
docker-compose up -d --build
```
默认通过 Nginx 暴露 `http://localhost:4002`
当前 Compose 服务:
- `web`:前端静态站点,暴露 `http://localhost:4002`
- `api`NestJS API暴露 `http://localhost:3002`
- `db`PostgreSQL 16暴露 `localhost:5433`
- `uploads_data`:后端文件持久化 volume。
构建流程:
- `Dockerfile` 使用 Node 构建 `dist/`
- 运行阶段使用 `nginx:alpine` 托管静态文件。
- `Dockerfile.server` 构建并运行 NestJS API。
- `nginx.conf` 已配置 SPA 路由回退和 `/api` 反向代理。
## 部署边界
当前后端已承载登录认证、数据库 Session、Dashboard、报告、报告媒体关系、模板、字段库、通用文件/签名文件、视频/关键帧文件、用户管理、部门模板授权、系统设置、AI 代理、语音代理、HTML 清洗和审计日志查询。生产化前还需要补齐第三方代理调用摘要、限流、备份恢复、对象存储和更完整的旧数据迁移。