feat:初版
This commit is contained in:
49
apps/api/app/main.py
Normal file
49
apps/api/app/main.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from .core import get_settings, logger
|
||||
from .api import translate_router, admin_router, provider_router, stats_router
|
||||
from .services import cache_service, rate_limit_service, llm_service, stats_service
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
logger.info("Starting up...")
|
||||
await cache_service.connect()
|
||||
await rate_limit_service.connect()
|
||||
await llm_service.connect()
|
||||
await stats_service.connect()
|
||||
yield
|
||||
logger.info("Shutting down...")
|
||||
await cache_service.disconnect()
|
||||
await rate_limit_service.disconnect()
|
||||
await llm_service.disconnect()
|
||||
await stats_service.disconnect()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="AI Translator API",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(translate_router)
|
||||
app.include_router(admin_router)
|
||||
app.include_router(provider_router)
|
||||
app.include_router(stats_router)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user