📚 新增部署文档 DEPLOY.md
内容: - 快速启动步骤 - 常见问题排查 - 配置文件说明 - 最佳实践建议 帮助避免部署问题
This commit is contained in:
118
DEPLOY.md
Normal file
118
DEPLOY.md
Normal file
@@ -0,0 +1,118 @@
|
||||
# 🦀 龙虾监控中心 - 部署指南
|
||||
|
||||
## 📋 服务架构
|
||||
|
||||
```
|
||||
前端 (React) 后端 (Django)
|
||||
↓ ↓
|
||||
端口 4000 端口 9000
|
||||
↓ ↓
|
||||
build/静态文件 API 服务
|
||||
```
|
||||
|
||||
## 🚀 快速启动
|
||||
|
||||
### 1. 启动后端
|
||||
|
||||
```bash
|
||||
cd code/backend
|
||||
source venv/bin/activate
|
||||
python manage.py runserver 0.0.0.0:9000
|
||||
```
|
||||
|
||||
### 2. 构建并启动前端
|
||||
|
||||
```bash
|
||||
cd code/frontend
|
||||
npm run build
|
||||
cd build
|
||||
python3 -m http.server 4000 --bind 127.0.0.1
|
||||
```
|
||||
|
||||
### 3. 访问
|
||||
|
||||
- 前端:http://localhost:4000/
|
||||
- 后端 API: http://localhost:9000/api/
|
||||
|
||||
## ⚠️ 常见问题
|
||||
|
||||
### Q: 前端显示"加载中..."
|
||||
**A**: 检查后端是否在 9000 端口运行
|
||||
```bash
|
||||
curl http://localhost:9000/api/agents/
|
||||
```
|
||||
|
||||
### Q: API 返回 404
|
||||
**A**: 确认前端 API 配置正确
|
||||
- 检查 `src/pages/Dashboard/index.js` 中的 `API_BASE`
|
||||
- 应该是 `http://localhost:9000/api`
|
||||
|
||||
### Q: 代码改了但不生效
|
||||
**A**: 需要重新 build 前端
|
||||
```bash
|
||||
cd code/frontend
|
||||
npm run build # 重新构建
|
||||
# 然后重启前端服务
|
||||
```
|
||||
|
||||
## 🔧 配置文件
|
||||
|
||||
### 前端 API 配置
|
||||
文件:`code/frontend/src/pages/Dashboard/index.js`
|
||||
```javascript
|
||||
const API_BASE = 'http://localhost:9000/api';
|
||||
```
|
||||
|
||||
### 后端端口
|
||||
文件:`code/backend/backend/settings.py`
|
||||
```bash
|
||||
# 启动时指定端口
|
||||
python manage.py runserver 0.0.0.0:9000
|
||||
```
|
||||
|
||||
## 📦 依赖安装
|
||||
|
||||
### 后端
|
||||
```bash
|
||||
cd code/backend
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 前端
|
||||
```bash
|
||||
cd code/frontend
|
||||
npm install
|
||||
```
|
||||
|
||||
## 🎯 最佳实践
|
||||
|
||||
1. **启动前先 git pull**
|
||||
```bash
|
||||
git pull origin main
|
||||
```
|
||||
|
||||
2. **前端修改后重新 build**
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
3. **后端修改后重启服务**
|
||||
```bash
|
||||
# Ctrl+C 停止
|
||||
# 重新启动
|
||||
```
|
||||
|
||||
4. **检查服务状态**
|
||||
```bash
|
||||
# 检查后端
|
||||
curl http://localhost:9000/api/agents/
|
||||
|
||||
# 检查前端
|
||||
curl http://localhost:4000/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*最后更新:2026-04-04*
|
||||
Reference in New Issue
Block a user