Complete backend API and deployment guide

- Django REST API with lobster endpoints
- API views: list, detail, memory, tools
- Deployment guide with instructions
- Startup script for easy launch
- Requirements.txt for dependencies
- API URL routing
This commit is contained in:
2026-04-01 20:52:03 +08:00
parent 5386db423a
commit 4be901b1b0
9 changed files with 349 additions and 0 deletions

124
docs/部署指南.md Normal file
View File

@@ -0,0 +1,124 @@
# 部署指南
## 🚀 快速部署
### 1. 安装依赖
#### 后端
```bash
cd code/backend
pip3 install -r requirements.txt
```
#### 前端
```bash
cd code/frontend
npm install
```
### 2. 启动服务
#### 方法一:使用启动脚本
```bash
chmod +x start.sh
./start.sh
```
#### 方法二:手动启动
```bash
# 启动后端
cd code/backend
python3 manage.py runserver 0.0.0.0:8000
# 启动前端(新终端)
cd code/frontend
npm start
# 或
python3 -m http.server 3000
```
### 3. 访问
- **前端**: http://localhost:3000
- **后端 API**: http://localhost:8000/api/
- **API 文档**: http://localhost:8000/api/lobsters/
## 📊 API 接口
### 获取龙虾列表
```bash
curl http://localhost:8000/api/lobsters/
```
### 获取龙虾详情
```bash
curl http://localhost:8000/api/lobsters/1/
```
### 获取龙虾记忆
```bash
curl http://localhost:8000/api/lobsters/1/memory/
```
### 获取工具列表
```bash
curl http://localhost:8000/api/tools/
```
## 🔧 配置
### 环境变量
- `DEBUG`: 调试模式(默认 True
- `SECRET_KEY`: Django 密钥
- `ALLOWED_HOSTS`: 允许的主机
### 数据库
默认使用 SQLite无需配置。
## 📝 日志
- 后端日志:终端输出
- 前端日志:浏览器控制台
## 🐛 故障排查
### 端口被占用
```bash
# 查看占用端口的进程
lsof -i :8000
lsof -i :3000
# 杀死进程
kill -9 <PID>
```
### 依赖问题
```bash
# 重新安装依赖
pip3 install -r requirements.txt --force-reinstall
npm install --force
```
## 📦 生产部署
### 使用 Gunicorn
```bash
pip3 install gunicorn
gunicorn backend.wsgi:application --bind 0.0.0.0:8000
```
### 使用 Nginx 反向代理
```nginx
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
}
location /api/ {
proxy_pass http://localhost:8000;
}
}
```