Files
Pre_Seg_Server/工程分析/实现方案-2026-04-29-22-37-36.md

47 lines
1.5 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.md`
## 方案概述
服务器实际 IP 为 `192.168.3.11`。修复方案分三步:
1. 前端 `api.ts``baseURL` 改为服务器实际 IP
2. 后端 CORS 配置添加服务器 IP 对应的前端 origin
3. 重启前后端服务验证
## 根因分析
```
用户浏览器 → 访问 http://192.168.3.11:3000前端
↓ 前端代码运行
↓ api.ts 中 axios.post('http://localhost:8000/api/auth/login')
↓ 浏览器解析 localhost = 用户本地机器(非服务器)
↓ 用户本地 8000 端口无服务
↓ ERR_CONNECTION_REFUSED
```
## 修改文件清单
### 文件 1: `src/lib/api.ts`(修改)
- **修改类型**: 修改 baseURL
- **修改内容**: `http://localhost:8000``http://192.168.3.11:8000`
### 文件 2: `backend/config.py`(修改)
- **修改类型**: 扩展 CORS origins
- **修改内容**: `cors_origins``["http://localhost:3000"]` 扩展为 `["http://localhost:3000", "http://192.168.3.11:3000"]`
### 文件 3: `.env.example`(新增/修改)
- **修改类型**: 新增 VITE_API_BASE_URL 示例
- **修改内容**: 提供前端 baseURL 环境变量模板
## 新增依赖
## 兼容性分析
- localhost:3000 开发方式仍可用CORS 双 origin
- 局域网 IP 访问方式新增可用
- 回滚策略: 改回 localhost 即可
## 预估工作量
- 代码修改: 5 分钟
- 重启验证: 5 分钟