You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
"""
|
|
代码漏洞检测系统 - 后端主启动文件
|
|
"""
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.api import projects, scans, reports, vulnerabilities, files
|
|
from app.database import init_db
|
|
|
|
# 创建FastAPI应用
|
|
app = FastAPI(
|
|
title="代码漏洞检测系统",
|
|
description="基于AI增强的代码漏洞检测和报告生成系统",
|
|
version="1.0.0"
|
|
)
|
|
|
|
# 配置CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000"], # 前端地址
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 注册路由
|
|
app.include_router(projects.router, prefix="/api/projects", tags=["projects"])
|
|
app.include_router(scans.router, prefix="/api/scans", tags=["scans"])
|
|
app.include_router(reports.router, prefix="/api/reports", tags=["reports"])
|
|
app.include_router(vulnerabilities.router, prefix="/api/vulnerabilities", tags=["vulnerabilities"])
|
|
app.include_router(files.router, prefix="/api", tags=["files"])
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
"""应用启动时初始化数据库"""
|
|
init_db()
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
"""根路径健康检查"""
|
|
return {"message": "代码漏洞检测系统 API", "status": "running"}
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
"""健康检查接口"""
|
|
return {"status": "healthy"}
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(
|
|
"main:app",
|
|
host="0.0.0.0",
|
|
port=8000,
|
|
reload=True,
|
|
log_level="info"
|
|
)
|