Files
AIclinicalresearch/测试和启动.md
AI Clinical Dev Team 239c7ea85e feat: Day 21-22 - knowledge base frontend completed, fix CORS and file upload issues
- Complete knowledge base list and detail pages
- Complete document upload component
- Fix CORS config (add PUT/DELETE method support)
- Fix file upload issues (disabled state and beforeUpload return value)
- Add detailed debug logs (cleaned up)
- Create Day 21-22 completion summary document
2025-10-11 15:40:12 +08:00

203 lines
3.9 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.
# 系统启动和测试指南
## 🚀 快速启动
### 1. 启动后端服务
**打开第一个终端:**
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npm run dev
```
**预期输出:**
```
🚀 AI临床研究平台 - 后端服务器启动成功!
📍 服务地址: http://localhost:3001
🔍 健康检查: http://localhost:3001/health
```
**如果报错,检查:**
- ✅ PostgreSQL是否运行Docker: `docker ps`
- ✅ Redis是否运行Docker: `docker ps`
-`.env`文件是否配置了API Keys
---
### 2. 启动前端服务
**打开第二个终端:**
```powershell
cd d:\MyCursor\AIclinicalresearch\frontend
npm run dev
```
**预期输出:**
```
VITE v6.x.x ready in xxx ms
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
```
---
### 3. 访问系统
打开浏览器访问:**http://localhost:3000/**
---
## 🔧 常见问题排查
### 问题1获取项目列表失败
**原因:** 后端服务未启动或数据库连接失败
**解决方案:**
1. 检查后端是否启动:访问 http://localhost:3001/health
2. 检查数据库是否运行:
```powershell
docker ps
# 应该看到postgres和redis容器在运行
```
3. 如果数据库未启动:
```powershell
cd d:\MyCursor\AIclinicalresearch
docker-compose up -d
```
---
### 问题2创建项目失败500错误
**原因:** 数据库表未创建或后端代码错误
**解决方案:**
**步骤1检查数据库表是否存在**
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npx prisma studio
# 打开Prisma Studio检查是否有Project表
```
**步骤2如果表不存在运行迁移**
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npx prisma migrate dev
```
**步骤3查看后端日志**
- 在运行`npm run dev`的终端中查看错误日志
- 通常会显示具体的错误原因
---
### 问题3API请求404
**原因:** 代理配置或路由问题
**检查清单:**
1. ✅ 后端启动在3001端口
2. ✅ 前端启动在3000端口
3. ✅ `vite.config.ts`中配置了代理
4. ✅ API路由正确注册
---
## 📋 完整启动检查清单
### 前置条件
- [ ] Docker Desktop已安装并运行
- [ ] Node.js已安装v18+
- [ ] PostgreSQL容器已启动
- [ ] Redis容器已启动
- [ ] 后端依赖已安装(`npm install`
- [ ] 前端依赖已安装(`npm install`
- [ ] 后端`.env`文件已配置API Keys
- [ ] 数据库迁移已完成(`prisma migrate dev`
### 启动顺序
1. [ ] 启动Docker容器PostgreSQL + Redis
2. [ ] 启动后端服务3001端口
3. [ ] 启动前端服务3000端口
4. [ ] 访问浏览器测试
---
## 🧪 测试流程
### 1. 测试后端健康检查
```powershell
# 在浏览器或使用curl
curl http://localhost:3001/health
```
**预期响应:**
```json
{
"status": "ok",
"database": "connected",
"timestamp": "2025-10-10T..."
}
```
### 2. 测试获取智能体列表
```powershell
curl http://localhost:3001/api/v1/agents
```
**预期响应:**
```json
{
"success": true,
"data": [
{
"id": "topic-evaluation",
"name": "选题评价智能体",
...
}
]
}
```
### 3. 测试前端页面
1. 访问 http://localhost:3000/
2. 应该看到首页和12个智能体卡片
3. 创建新项目
4. 选择"选题评价智能体"进入对话
---
## 💡 调试技巧
### 查看后端日志
后端使用Pino日志启动时会显示所有请求和错误
### 查看前端控制台
按F12打开开发者工具查看
- ConsoleJavaScript错误
- NetworkAPI请求状态
### 查看数据库
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npx prisma studio
# 在浏览器中查看和编辑数据库内容
```
---
## 🆘 获取帮助
如果以上方法都无法解决问题,请提供:
1. 后端终端的完整日志
2. 前端浏览器控制台的错误信息
3. 访问 http://localhost:3001/health 的响应
4. `docker ps` 的输出