forked from Kexing/AI4SE_Practices
64 lines
1.3 KiB
Python
64 lines
1.3 KiB
Python
"""
|
|
AI4SE Survey API主应用
|
|
"""
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from api.routers import tools, test_results, test_tasks
|
|
from api import __version__
|
|
|
|
|
|
app = FastAPI(
|
|
title="AI4SE Survey API",
|
|
description="AI驱动的软件工程工具调研API",
|
|
version=__version__,
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
openapi_url="/openapi.json", # 明确指定OpenAPI JSON路径
|
|
)
|
|
|
|
|
|
# CORS配置
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # 生产环境应该设置具体的域名
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
# 注册路由
|
|
app.include_router(tools.router)
|
|
app.include_router(test_results.router)
|
|
app.include_router(test_tasks.router)
|
|
|
|
|
|
@app.get("/", tags=["root"])
|
|
async def root():
|
|
"""
|
|
API根路径
|
|
"""
|
|
return {
|
|
"name": "AI4SE Survey API",
|
|
"version": __version__,
|
|
"description": "AI驱动的软件工程工具调研API",
|
|
"docs": "/docs",
|
|
"redoc": "/redoc",
|
|
}
|
|
|
|
|
|
@app.get("/health", tags=["health"])
|
|
async def health():
|
|
"""
|
|
健康检查
|
|
"""
|
|
return {"status": "healthy"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|