Initialize uv-managed FastAPI backend

This commit is contained in:
2026-09-15 19:00:10 +08:00
commit fd30c83152
8 changed files with 482 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
# Python 后端服务器
使用 FastAPI 开发,依赖和虚拟环境统一由 **uv** 管理。
## 开发
```sh
uv sync
uv run uvicorn backend_server.main:app --reload --host 127.0.0.1 --port 8000
```
- 健康检查:`http://localhost:8000/health`
- API 文档:`http://localhost:8000/docs`
- OpenAPI:`http://localhost:8000/openapi.json`
默认允许来自 `http://localhost:3000`、`http://localhost:5173` 的浏览器请求。
通过环境变量配置逗号分隔的允许来源:
```sh
CORS_ORIGINS=https://your-frontend.example uv run uvicorn backend_server.main:app
```
## 检查
```sh
uv run pytest
uv run ruff check .
uv run ruff format --check .
```
提交 `uv.lock`,在其他电脑使用 `uv sync --locked` 复现依赖。