Initialize backendized SurClaw report system
- Add React/Vite frontend for login, dashboard, reports, templates, users, settings, AI, speech, and media workflows. - Add NestJS/Prisma/PostgreSQL backend with auth, dashboard stats, reports, templates, users, departments, settings, files, AI, speech, audit logs, and HTML sanitization. - Add Prisma schema, migrations, seed data, persistent app sessions, Docker/Nginx deployment files, and upload volume configuration. - Add Vitest, Playwright, backend integration tests, and project documentation for requirements, design, permissions, API contracts, testing, deployment, security, and progress. - Configure production local fallback switch and remove unused Gemini direct dependency/env wiring.
This commit is contained in:
92
docs/deployment.md
Normal file
92
docs/deployment.md
Normal file
@@ -0,0 +1,92 @@
|
||||
# 部署运行
|
||||
|
||||
## 本地开发
|
||||
|
||||
前端:
|
||||
|
||||
```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 清洗和第一版审计。生产化前还需要补齐查看日志、第三方代理调用摘要、限流、备份恢复、对象存储和更完整的旧数据迁移。
|
||||
Reference in New Issue
Block a user