93 lines
3.4 KiB
Python
93 lines
3.4 KiB
Python
import sys
|
||
import os
|
||
from pathlib import Path
|
||
|
||
# 添加项目根目录到 Python 路径
|
||
# 无论从哪里运行,都能正确找到 app 模块
|
||
current_file = Path(__file__).resolve()
|
||
project_root = current_file.parent.parent # backend/
|
||
if str(project_root) not in sys.path:
|
||
sys.path.insert(0, str(project_root))
|
||
|
||
import uvicorn
|
||
from fastapi import FastAPI, Request, HTTPException
|
||
from fastapi.middleware.cors import CORSMiddleware
|
||
from fastapi.staticfiles import StaticFiles
|
||
from fastapi.openapi.docs import get_swagger_ui_html
|
||
from app.api.endpoints import auth, users, meetings, tags, admin, admin_dashboard, tasks, prompts, knowledge_base, client_downloads, voiceprint, audio, dict_data, hot_words, external_apps, terminals
|
||
from app.core.config import UPLOAD_DIR, API_CONFIG
|
||
|
||
app = FastAPI(
|
||
title="iMeeting API",
|
||
description="iMeeting API说明",
|
||
version="1.1.0",
|
||
docs_url=None, # 禁用默认docs,使用自定义CDN
|
||
redoc_url=None
|
||
)
|
||
|
||
# 添加CORS中间件
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=["*"],
|
||
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.include_router(tags.router, prefix="/api", tags=["Tags"])
|
||
app.include_router(admin.router, prefix="/api", tags=["Admin"])
|
||
app.include_router(admin_dashboard.router, prefix="/api", tags=["AdminDashboard"])
|
||
app.include_router(tasks.router, prefix="/api", tags=["Tasks"])
|
||
app.include_router(prompts.router, prefix="/api", tags=["Prompts"])
|
||
app.include_router(knowledge_base.router, prefix="/api", tags=["KnowledgeBase"])
|
||
app.include_router(client_downloads.router, prefix="/api", tags=["ClientDownloads"])
|
||
app.include_router(external_apps.router, prefix="/api", tags=["ExternalApps"])
|
||
app.include_router(dict_data.router, prefix="/api", tags=["DictData"])
|
||
app.include_router(voiceprint.router, prefix="/api", tags=["Voiceprint"])
|
||
app.include_router(audio.router, prefix="/api", tags=["Audio"])
|
||
app.include_router(hot_words.router, prefix="/api", tags=["HotWords"])
|
||
app.include_router(terminals.router, prefix="/api", tags=["Terminals"])
|
||
|
||
@app.get("/docs", include_in_schema=False)
|
||
async def custom_swagger_ui_html():
|
||
"""自定义Swagger UI,使用国内可访问的CDN"""
|
||
return get_swagger_ui_html(
|
||
openapi_url=app.openapi_url,
|
||
title=app.title + " - Swagger UI",
|
||
oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
|
||
swagger_js_url="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui-bundle.js",
|
||
swagger_css_url="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui.css",
|
||
)
|
||
|
||
@app.get("/")
|
||
def read_root():
|
||
return {"message": "Welcome to iMeeting API"}
|
||
|
||
@app.get("/health")
|
||
def health_check():
|
||
"""健康检查端点"""
|
||
return {
|
||
"status": "healthy",
|
||
"service": "iMeeting API",
|
||
"version": "1.1.0"
|
||
}
|
||
|
||
if __name__ == "__main__":
|
||
# 简单的uvicorn配置,避免参数冲突
|
||
uvicorn.run(
|
||
"app.main:app",
|
||
host=API_CONFIG['host'],
|
||
port=API_CONFIG['port'],
|
||
limit_max_requests=1000,
|
||
timeout_keep_alive=30,
|
||
reload=True,
|
||
)
|