Files
Mdeical_Sur_Report/docs/deployment.md
admin 7c6449b7bd Standardize SurClaw ports away from defaults
- Change the API default listen port from 3000 to 3100 and include the Docker frontend origin in default CORS.

- Point Vite's default API proxy, Docker API container port, and Nginx upstream to 3100.

- Keep Docker host ports on 4002 for web, 3002 for API, and 5433 for PostgreSQL.

- Update environment examples and documentation to remove stale localhost:3000 guidance.
2026-05-02 02:17:07 +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:3100`
后端:
```bash
cp .env.example .env
npm run prisma:generate
npm run server:dev
```
本地直接运行 API 默认监听 `0.0.0.0:3100`,健康检查为:
```text
http://localhost:3100/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 监听端口。本地直接运行默认 `3100`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:3100`;连接 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 清洗和审计日志查询。生产化前还需要补齐第三方代理调用摘要、限流、备份恢复、对象存储和更完整的旧数据迁移。