Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import uvicorn | |
| from app.api.graph import router as graph_router | |
| # 创建FastAPI应用 | |
| app = FastAPI( | |
| title="知识图谱 API", | |
| description="提供知识图谱数据查询和缓存管理功能", | |
| version="1.0.0" | |
| ) | |
| # 配置CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # 允许所有来源,生产环境应该指定前端域名 | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # 注册路由 | |
| app.include_router(graph_router) | |
| # 健康检查路由 | |
| async def health_check(): | |
| return {"status": "ok", "message": "API正常运行"} | |
| if __name__ == "__main__": | |
| uvicorn.run("app.main:app", host="0.0.0.0", port=5000, reload=True) | |