- Introduce `setup-certs.sh` script for generating trusted local TLS certificates using mkcert. - Add Nginx configuration files for local and Docker environments to handle HTTPS requests and proxy to backend services. - Update `docker-compose.yaml` to include Nginx service for unified TLS entry and adjust frontend service ports for local development. - Create `AGENTS.md` and `README.md` files to document the local HTTPS setup process and usage instructions. - Modify backend startup commands in `README.md` for consistency with new requirements. - Add `.gitignore` to exclude generated certificates from version control.
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
"""FastAPI 入口。挂载路由,放行前端跨域,启动时建表。
|
|
|
|
启动: uv run --with-requirements requirements.txt uvicorn app:app --reload --port 8000
|
|
|
|
路由分组(对齐 dograh 的 routes/ 结构):
|
|
/health 健康检查
|
|
/api/assistants 助手 CRUD
|
|
/api/credentials 模型凭证 CRUD(key 打码)
|
|
/ws/voice WebRTC 输出(浏览器)
|
|
/ws/stream WS 输出(裸音频流)
|
|
"""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
import config
|
|
import uvicorn
|
|
from db.session import init_db
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from routes import (
|
|
assistants,
|
|
credentials,
|
|
health,
|
|
knowledge_bases,
|
|
voice_webrtc,
|
|
voice_ws,
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_app: FastAPI):
|
|
await init_db() # MVP:启动建表;表稳定后切 alembic
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="AI Video Assistant 平台 - 后端", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=config.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(assistants.router)
|
|
app.include_router(credentials.router)
|
|
app.include_router(knowledge_bases.router)
|
|
app.include_router(voice_webrtc.router)
|
|
app.include_router(voice_ws.router)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("app:app", host=config.HOST, port=config.PORT, reload=True)
|