Files
hms/wiki/infrastructure.md
iven 945ccd64ba
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled
fix: 全面 QA 审计修复 — 安全加固/代码质量/跨平台一致性/测试覆盖
Phase 0 安全热修复 (CRITICAL):
- 外部化微信 appid/secret 到 ERP__WECHAT__APPID/SECRET 环境变量
- 正确连接 HealthCrypto 到 ERP__HEALTH__AES_KEY/HMAC_KEY 环境变量
- 外部化小程序加密密钥到 TARO_APP_ENCRYPTION_KEY 环境变量
- 移除小程序 auth store 中的敏感信息 console.log

Phase 1 安全加固:
- 微信自动注册 display_name 添加 sanitize 防止 XSS
- 测试数据库凭据改为从 TEST_DB_URL 环境变量读取

Phase 2 代码质量:
- 提取 useThemeMode hook 消除 22 处重复暗色模式检测
- 提取共享健康常量到 constants/health.ts
- 拆分 patient_service.rs 脱敏函数到 masking.rs
- 移除未使用的 i18next/react-i18next 依赖
- 移除未使用的 api/errors.ts 和 erp-auth/anyhow 依赖

Phase 3 测试覆盖:
- 新增 5 个患者模块集成测试 (CRUD/租户隔离/验证/软删除)

Phase 4 跨平台一致性:
- 统一小程序 Patient.birthday → birth_date 匹配后端
- 统一小程序 Appointment.time_slot → start_time/end_time 匹配后端

Phase 5 架构:
- 微信登录添加多租户 TODO 注释
- 更新 wiki/infrastructure.md 环境变量文档
2026-04-25 10:00:49 +08:00

126 lines
4.4 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.
---
title: 开发环境
updated: 2026-04-23
status: stable
tags: [infrastructure, dev-environment, windows, postgresql]
---
# 开发环境
> 从 [[index]] 导航。关联: [[erp-server]] [[database]] [[frontend]] [[testing]]
>
> **本页是连接信息、启动命令、登录凭据的单一真相源。** 其他页面引用此处。
## 1. 设计决策
- **Windows 原生运行** — PostgreSQL/Redis/Rust/Node 直接在宿主机,不用 Docker
- **一键启动** — `dev.ps1` 管理前后端生命周期
- **环境变量优先** — 敏感配置通过 `ERP__` 前缀环境变量覆盖 TOML
## 2. 关键文件 + 连接信息
### 核心文件
| 文件 | 职责 |
|------|------|
| `dev.ps1` | 一键启动/停止(自动清理端口 5174-5189 |
| `crates/erp-server/config/default.toml` | 默认配置模板 |
| `docker/docker-compose.yml` | 可选 Docker 配置 |
### 服务连接
| 服务 | 地址 | 用途 |
|------|------|------|
| PostgreSQL 18 | `postgres://postgres:123123@localhost:5432/erp` | 主数据库 |
| Redis 7 | `redis://:redis_KBCYJk@129.204.154.246:6379` (云端) | 缓存 + 限流 |
| 后端 API | `http://localhost:3000/api/v1` | Axum 服务 |
| 前端 SPA | `http://localhost:5174` | Vite 开发服务器 |
| 微信小程序 | 微信开发者工具 | 患者端小程序(`apps/miniprogram/dist/` |
### 登录凭据
```
用户名: admin 密码: Admin@2026
```
psql: `D:\postgreSQL\bin\psql.exe -U postgres -h localhost -d erp`
### 必须设置的环境变量
| 变量 | 开发值 |
|------|--------|
| `ERP__DATABASE__URL` | `postgres://postgres:123123@localhost:5432/erp` |
| `ERP__JWT__SECRET` | `dev-secret-key-change-in-prod` |
| `ERP__AUTH__SUPER_ADMIN_PASSWORD` | `Admin@2026` |
| `ERP__REDIS__URL` | `redis://:redis_KBCYJk@129.204.154.246:6379` |
| `ERP__WECHAT__APPID` | `wx20f4ef9cc2ec66c5` |
| `ERP__WECHAT__SECRET` | 微信小程序 Secret |
| `ERP__HEALTH__AES_KEY` | 64 字符 hex 编码32 字节) |
| `ERP__HEALTH__HMAC_KEY` | 64 字符 hex 编码32 字节) |
> 所有八个在 `default.toml` 中为 `__MUST_SET_VIA_ENV__` 占位符
> 开发环境 AES/HMAC 密钥生成: `python -c "import secrets; print(secrets.token_hex(32))"`
### 微信小程序配置
| 配置 | 位置 | 说明 |
|------|------|------|
| AppID/Secret | 环境变量 `ERP__WECHAT__APPID` / `ERP__WECHAT__SECRET` | 微信登录凭据 |
| 加密密钥 | 环境变量 `TARO_APP_ENCRYPTION_KEY` | 小程序本地存储加密密钥 |
| API URL | `apps/miniprogram/config/index.ts` `defineConstants` | 编译时注入,默认 `http://localhost:3000/api/v1` |
| 开发者工具 | `apps/miniprogram/project.config.json` | `urlCheck: false`AppID `wx20f4ef9cc2ec66c5` |
> 微信凭据和加密密钥通过环境变量注入,不硬编码在源码中
### 集成契约
| 方向 | 模块 | 触发时机 |
|------|------|---------|
| 提供 → | [[erp-server]] | 数据库/Redis 连接 |
| 提供 → | [[frontend]] | Vite 代理目标 |
| 提供 → | [[testing]] | 测试环境配置 |
| 提供 → | [[miniprogram]] | 后端 API + 微信登录 |
## 3. 代码逻辑
### 一键启动(推荐)
```powershell
.\dev.ps1 # 启动后端 + 前端
.\dev.ps1 -Status # 查看端口状态
.\dev.ps1 -Stop # 停止所有服务
.\dev.ps1 -Restart # 重启所有服务
```
### 手动启动
```powershell
# 后端(必须从 crates/erp-server 目录)
cd crates/erp-server
$env:ERP__DATABASE__URL = "postgres://postgres:123123@localhost:5432/erp"
$env:ERP__JWT__SECRET = "dev-secret-key-change-in-prod"
$env:ERP__AUTH__SUPER_ADMIN_PASSWORD = "Admin@2026"
cargo run -p erp-server
# 前端
cd apps/web && pnpm install && pnpm dev
```
**不变量**: 后端必须从 `crates/erp-server/` 目录启动或通过环境变量覆盖所有配置
**不变量**: Vite 固定端口 5174`--strictPort`),前端代理 `/api` → 后端 3000
## 4. 活跃问题 + 陷阱
⚠️ Redis 不可达时限流自动降级为 fail-open放行所有请求
⚠️ Docker Compose 配置保留在 `docker/` 下但日常开发不依赖
⚠️ 首次 `cargo run` 编译整个 workspace 较慢(含 wasmtime后续增量快
## 5. 变更记录
| 日期 | 变更 |
|------|------|
| 2026-04-25 | 外部化微信凭据和健康加密密钥为环境变量;添加 4 个新的必设环境变量 |
| 2026-04-24 | 添加微信小程序配置信息和集成契约 |
| 2026-04-23 | 重构为 5 节结构,确立为连接信息的单一真相源 |