1.9 KiB
1.9 KiB
🦀 龙虾监控中心 - 部署指南
📋 服务架构
前端 (React) 后端 (Django)
↓ ↓
端口 4000 端口 9000
↓ ↓
build/静态文件 API 服务
🚀 快速启动
1. 启动后端
cd code/backend
source venv/bin/activate
python manage.py runserver 0.0.0.0:9000
2. 构建并启动前端
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 端口运行
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 前端
cd code/frontend
npm run build # 重新构建
# 然后重启前端服务
🔧 配置文件
前端 API 配置
文件:code/frontend/src/pages/Dashboard/index.js
const API_BASE = 'http://localhost:9000/api';
后端端口
文件:code/backend/backend/settings.py
# 启动时指定端口
python manage.py runserver 0.0.0.0:9000
📦 依赖安装
后端
cd code/backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
前端
cd code/frontend
npm install
🎯 最佳实践
-
启动前先 git pull
git pull origin main -
前端修改后重新 build
npm run build -
后端修改后重启服务
# Ctrl+C 停止 # 重新启动 -
检查服务状态
# 检查后端 curl http://localhost:9000/api/agents/ # 检查前端 curl http://localhost:4000/
最后更新:2026-04-04