添加API密钥管理、模型服务和安全服务,并优化FastAPI应用程序配置

This commit is contained in:
yinpeng
2024-12-15 11:08:35 +08:00
parent 03c201c849
commit c56bea0b25
15 changed files with 638 additions and 438 deletions
+38
View File
@@ -0,0 +1,38 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import logging
from app.api.routes import router
import uvicorn
# 配置日志
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
app = FastAPI()
# 允许跨域
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 包含所有路由
app.include_router(router)
@app.get("/health")
@app.get("/")
async def health_check():
logger.info("Health check endpoint called")
return {"status": "healthy"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8001)