Files
DP/Server/README.md

104 lines
2.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.
# ServerFastAPI 后端)
当前目录是 DesignerCEP 的主后端服务。
## 1. 当前目录结构(关键)
```text
Server/
├── app/ # FastAPI 代码
│ ├── api/v1/ # 接口路由
│ ├── core/ # 配置与安全
│ ├── models/ # ORM 模型
│ ├── schemas/ # Pydantic Schema
│ ├── services/ # 业务服务
│ ├── db.py # SQLAlchemy 初始化与 seed
│ └── main.py # 应用入口
├── archives/ # 上传版本包归档目录
├── debug_images/ # 调试图片输出
├── docker-compose.yml # Docker 编排backend + mysql + pma + portainer
├── Dockerfile # 后端镜像
├── requirements.txt # Python 依赖
├── start.sh # 容器启动脚本
├── .env.example # 配置模板(推荐复制后本地填写)
└── .env # 运行配置(敏感)
```
## 2. 本地运行
```bash
cd Server
copy .env.example .env
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
```
检查服务:
```bash
curl http://localhost:8000/health
```
## 3. Docker 运行
```bash
cd Server
docker-compose up -d --build
docker-compose ps
docker-compose logs -f backend
```
停止服务:
```bash
docker-compose down
```
## 4. 配置说明(来自 `app/core/config.py`
主要环境变量(优先使用 `AI_*`
- `ENV`development / production
- `DATABASE_URL`
- `SECRET_KEY`
- `ADMIN_TOKEN`
- `ALLOWED_ORIGINS`
- `SMTP_*`
- `QINIU_*`
- `AI_API_KEY``AI_BASE_URL``AI_MODEL`
- `AI_VISION_MODEL``AI_IMAGE_EDIT_MODEL`
- `QINIU_DOMAIN`
## 5. 数据库迁移
推荐使用 Alembic
```bash
cd Server
.venv\Scripts\python -m alembic upgrade head
```
新增字段后生成迁移:
```bash
.venv\Scripts\python -m alembic revision --autogenerate -m "describe_change"
```
## 6. 接口前缀与入口
- API 前缀:`/api/v1`
- 健康检查:`GET /health`
- 启动入口:`app/main.py`
## 7. 关于静态文件
当前仓库中没有 `Server/static/app/` 目录。
在线部署场景下,前端静态资源由 Caddy/Nginx 单独托管(仓库根目录 `Caddyfile` 示例为 `/var/www/app`)。
## 8. 安全注意事项
- `Server/.env` 含真实密钥,不应继续明文共享。
- 启动时如果检测到默认密钥,后端会输出配置警告。
- 部署前请至少轮换:`SECRET_KEY``ADMIN_TOKEN`、数据库密码、AI 与云存储密钥。