steam-server/app/main.py

26 lines
726 B
Python
Raw Normal View History

2024-12-12 20:04:36 +08:00
from app.middleware.cors import add_cors_middleware
2024-12-13 18:21:25 +08:00
from app.middleware.security import add_security_middleware
2024-12-12 20:04:36 +08:00
from app.routes import websocket, stream
from app.tasks.cleanup_task import cleanup_streams
from fastapi import FastAPI
from contextlib import asynccontextmanager
import asyncio
@asynccontextmanager
async def lifespan(app: FastAPI):
# 启动定时清理任务
asyncio.create_task(cleanup_streams())
yield # FastAPI 会在这里执行应用关闭时的清理任务
print("停止服务")
app = FastAPI(lifespan=lifespan)
# 添加跨域中间件
add_cors_middleware(app)
2024-12-13 18:21:25 +08:00
# 添加鉴权中间件
add_security_middleware(app)
2024-12-12 20:04:36 +08:00
app.include_router(websocket.router)
app.include_router(stream.router)
2024-12-13 18:21:25 +08:00