imetting_backend/app/main.py

78 lines
2.7 KiB
Python
Raw Normal View History

2025-12-11 08:48:12 +00:00
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))
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
2026-01-16 02:07:41 +00:00
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
2025-09-26 07:47:37 +00:00
from app.core.config import UPLOAD_DIR, API_CONFIG
2025-08-05 01:46:40 +00:00
app = FastAPI(
title="iMeeting API",
description="智慧会议系统API",
2025-09-09 03:35:56 +00:00
version="1.0.2"
2025-08-05 01:46:40 +00:00
)
# 添加CORS中间件
app.add_middleware(
CORSMiddleware,
2025-10-16 03:09:19 +00:00
allow_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"])
2025-09-19 08:51:07 +00:00
app.include_router(tags.router, prefix="/api", tags=["Tags"])
2025-09-25 03:48:02 +00:00
app.include_router(admin.router, prefix="/api", tags=["Admin"])
2025-12-11 08:48:12 +00:00
app.include_router(admin_dashboard.router, prefix="/api", tags=["AdminDashboard"])
2025-09-30 04:14:19 +00:00
app.include_router(tasks.router, prefix="/api", tags=["Tasks"])
app.include_router(prompts.router, prefix="/api", tags=["Prompts"])
2025-10-16 03:09:19 +00:00
app.include_router(knowledge_base.router, prefix="/api", tags=["KnowledgeBase"])
2025-12-11 08:48:12 +00:00
app.include_router(client_downloads.router, prefix="/api", tags=["ClientDownloads"])
2026-01-16 02:07:41 +00:00
app.include_router(external_apps.router, prefix="/api", tags=["ExternalApps"])
2025-12-18 11:58:38 +00:00
app.include_router(dict_data.router, prefix="/api", tags=["DictData"])
2025-10-31 06:54:54 +00:00
app.include_router(voiceprint.router, prefix="/api", tags=["Voiceprint"])
2025-12-11 08:48:12 +00:00
app.include_router(audio.router, prefix="/api", tags=["Audio"])
2026-01-09 08:06:24 +00:00
app.include_router(hot_words.router, prefix="/api", tags=["HotWords"])
2025-08-05 01:46:40 +00:00
@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",
2025-09-26 07:47:37 +00:00
"version": "1.0.2"
2025-09-03 10:11:07 +00:00
}
2025-08-05 01:46:40 +00:00
if __name__ == "__main__":
2025-09-03 10:11:07 +00:00
# 简单的uvicorn配置避免参数冲突
uvicorn.run(
2025-12-11 08:48:12 +00:00
"app.main:app",
host=API_CONFIG['host'],
2025-09-03 10:11:07 +00:00
port=API_CONFIG['port'],
limit_max_requests=1000,
timeout_keep_alive=30,
reload=True,
2025-12-11 08:48:12 +00:00
)