import os import sys BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, BASE_DIR) from views import lifespan from fastapi.middleware.cors import CORSMiddleware from fastapi import FastAPI from foundation.logger.loggering import server_logger from views.test_views import test_router # 创建 FastAPI 应用 app = FastAPI( title=" Agent API", version="0.2", description=" Agent API", lifespan=lifespan ) app.include_router(test_router) # 添加 CORS 中间件 app.add_middleware( CORSMiddleware, allow_origins=["*"], # 允许所有的来源 allow_credentials=True, allow_methods=["*"], # 允许的HTTP方法 allow_headers=["*"], # 允许的请求头 ) server_logger.info(msg="APP init successfully") # 运行Uvicorn服务器 if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8001,reload=True)