50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
from routers import algorithms, events, devices, dashboard, monitors, alarms, scenes, upload, auth
|
|
from core.database import engine
|
|
from models.base import Base
|
|
|
|
# 创建数据库表
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="边检CV算法接口服务",
|
|
description="边检计算机视觉算法管理系统API",
|
|
version="1.0.0"
|
|
)
|
|
|
|
# 配置CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # 生产环境中应该指定具体域名
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 静态文件服务
|
|
app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads")
|
|
|
|
# 注册路由
|
|
app.include_router(algorithms.router, prefix="/api/algorithms", tags=["算法管理"])
|
|
app.include_router(events.router, prefix="/api/events", tags=["事件管理"])
|
|
app.include_router(devices.router, prefix="/api/devices", tags=["设备管理"])
|
|
app.include_router(dashboard.router, prefix="/api/dashboard", tags=["仪表板"])
|
|
app.include_router(monitors.router, prefix="/api/monitors", tags=["监控管理"])
|
|
app.include_router(alarms.router, prefix="/api/alarms", tags=["告警管理"])
|
|
app.include_router(scenes.router, prefix="/api/scenes", tags=["场景管理"])
|
|
app.include_router(upload.router, prefix="/api/upload", tags=["文件上传"])
|
|
app.include_router(auth.router, prefix="/api/auth", tags=["用户认证"])
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "边检CV算法接口服务"}
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "healthy"}
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True, workers=10) |