mottery/backend/app/main.py

61 lines
1.8 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.core.config import settings
from app.api.v1.lottery import router as lottery_router
from app.api.endpoints.analysis import router as analysis_router
from app.api.endpoints.advanced_analysis import router as advanced_analysis_router
from app.api.endpoints.prediction import router as prediction_router
from app.api.endpoints.bet_history import router as bet_history_router
from app.core.database import Base, engine
# 创建数据库表
Base.metadata.create_all(bind=engine)
app = FastAPI(
title=settings.PROJECT_NAME,
openapi_url=f"{settings.API_V1_STR}/openapi.json"
)
# 配置CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 允许所有来源
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 注册路由
app.include_router(
lottery_router, prefix=f"{settings.API_V1_STR}/lottery", tags=["lottery"])
app.include_router(
analysis_router, prefix=f"{settings.API_V1_STR}/analysis", tags=["analysis"])
app.include_router(
advanced_analysis_router, prefix=f"{settings.API_V1_STR}/advanced-analysis", tags=["advanced-analysis"])
app.include_router(
prediction_router, prefix=f"{settings.API_V1_STR}/prediction", tags=["prediction"])
app.include_router(
bet_history_router, prefix=f"{settings.API_V1_STR}/lottery/bet-history", tags=["bet-history"])
@app.get("/")
def read_root():
"""根路径,用于健康检查"""
return {
"message": "欢迎使用彩票数据分析系统",
"version": "1.0.0",
"status": "running",
"docs": "/docs"
}
@app.get("/health")
def health_check():
"""健康检查端点"""
return {"status": "healthy", "timestamp": "2024-01-01T00:00:00Z"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)