Files
Pre_Seg_Server/工程分析/需求分析-2026-04-29-22-37-36.md

43 lines
1.7 KiB
Markdown
Raw Permalink 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.
# 需求分析 - 2026-04-29-22-37-36
## 需求来源
- 提出时间: 2026-04-29-22-37-36
- 需求类型: 缺陷修复
## 原始需求描述
用户登录失败,浏览器控制台报错:
```
POST http://localhost:8000/api/auth/login net::ERR_CONNECTION_REFUSED
```
## 需求拆解
### 需求 1: 修复前端 baseURL 配置
- **详细描述**: `src/lib/api.ts``baseURL` 硬编码为 `http://localhost:8000`,当用户通过非 localhost 地址访问前端时,浏览器将 localhost 解析为客户端本地机器而非服务器,导致连接拒绝
- **优先级**: P0-阻塞
- **影响范围**: `src/lib/api.ts`
- **验收标准**: 前端可通过局域网 IP 正确访问后端
### 需求 2: 修复后端 CORS 配置
- **详细描述**: `backend/config.py``cors_origins` 仅允许 `http://localhost:3000`,需添加服务器实际 IP 地址的前端 origin
- **优先级**: P0-阻塞
- **影响范围**: `backend/config.py`, `backend/main.py`
- **验收标准**: 后端接受来自服务器 IP:3000 的跨域请求
### 需求 3: 添加 baseURL 可配置机制(可选增强)
- **详细描述**: 通过 `.env` 或运行时代码自动检测服务器 IP使 baseURL 不再硬编码
- **优先级**: P1-高
- **影响范围**: `src/lib/api.ts`
- **验收标准**: 无需修改代码即可适配不同部署环境
## 约束条件
- 不破坏现有 localhost 开发体验
- 保持中文界面不变
- 最小修改原则
## 风险评估
| 风险点 | 影响 | 缓解措施 |
|--------|------|----------|
| 修改后 localhost 开发失效 | 高 | 同时保留 localhost 和 IP 两种访问方式 |
| CORS 配置过于宽泛 | 中 | 仅添加必要的 IP origin不开放通配符 |