imetting_backend/main.py

72 lines
2.1 KiB
Python
Raw Normal View History

2025-08-05 01:46:40 +00:00
import uvicorn
2025-09-03 10:11:07 +00:00
from fastapi import FastAPI, Request, HTTPException
2025-08-05 01:46:40 +00:00
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from app.api.endpoints import auth, users, meetings
2025-09-03 10:11:07 +00:00
from app.core.config import UPLOAD_DIR, API_CONFIG, MAX_FILE_SIZE
2025-08-05 01:46:40 +00:00
import os
app = FastAPI(
title="iMeeting API",
description="智慧会议系统API",
version="1.0.0"
)
2025-09-03 10:11:07 +00:00
# 添加请求体大小检查中间件
@app.middleware("http")
async def check_content_size(request: Request, call_next):
# 检查Content-Length头
content_length = request.headers.get("content-length")
if content_length:
content_length = int(content_length)
if content_length > MAX_FILE_SIZE:
raise HTTPException(status_code=413, detail=f"Request entity too large. Maximum size is {MAX_FILE_SIZE//1024//1024}MB")
response = await call_next(request)
return response
2025-08-05 01:46:40 +00:00
# 添加CORS中间件
app.add_middleware(
CORSMiddleware,
2025-09-03 10:11:07 +00:00
# allow_origins=API_CONFIG['cors_origins'],
2025-08-05 01:46:40 +00:00
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 静态文件服务 - 提供音频文件下载
if UPLOAD_DIR.exists():
app.mount("/uploads", StaticFiles(directory=str(UPLOAD_DIR)), name="uploads")
# 包含API路由
app.include_router(auth.router, prefix="/api", tags=["Authentication"])
app.include_router(users.router, prefix="/api", tags=["Users"])
app.include_router(meetings.router, prefix="/api", tags=["Meetings"])
@app.get("/")
def read_root():
return {"message": "Welcome to iMeeting API"}
2025-09-03 10:11:07 +00:00
@app.get("/health")
def health_check():
"""健康检查端点"""
return {
"status": "healthy",
"service": "iMeeting API",
"version": "1.0.0"
}
2025-08-05 01:46:40 +00:00
if __name__ == "__main__":
2025-09-03 10:11:07 +00:00
# 简单的uvicorn配置避免参数冲突
uvicorn.run(
"main:app",
host=API_CONFIG['host'],
port=API_CONFIG['port'],
limit_max_requests=1000,
timeout_keep_alive=30,
reload=True,
# 设置更大的请求体限制以支持音频文件上传
h11_max_incomplete_event_size=104857600, # 100MB
)