From 2fdfd63370946430cde38c27379e84b8b78d3c72 Mon Sep 17 00:00:00 2001 From: zlgecc <103418489+zlgecc@users.noreply.github.com> Date: Wed, 6 Aug 2025 11:18:56 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=89=8D=E7=AB=AF=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/.gitignore | 91 +++++++++++++++++++++++++++++++++++++++++++++++ server/app.py | 12 +++++-- 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 server/.gitignore diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..c97269c --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,91 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so +*.pyd + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# VS Code +.vscode/ + +# Environment variables +.env +.env.* +.venv/ +venv/ +ENV/ +env/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# PyCharm +.idea/ + +# Local conda environments +.conda/ +conda-meta/ + +# Windows +Thumbs.db +ehthumbs.db +Desktop.ini + +# macOS +.DS_Store diff --git a/server/app.py b/server/app.py index ff0ab7a..ccef2d8 100644 --- a/server/app.py +++ b/server/app.py @@ -1,9 +1,11 @@ -from fastapi import FastAPI +from fastapi import FastAPI, Request +from fastapi.responses import FileResponse 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 +import os # 创建数据库表 Base.metadata.create_all(bind=engine) @@ -25,6 +27,9 @@ app.add_middleware( # 静态文件服务 app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads") +app.mount("/assets", StaticFiles(directory="dist/assets"), name="assets") +app.mount("/img", StaticFiles(directory="dist/assets"), name="img") + # 注册路由 app.include_router(algorithms.router, prefix="/api/algorithms", tags=["算法管理"]) @@ -39,6 +44,9 @@ app.include_router(auth.router, prefix="/api/auth", tags=["用户认证"]) @app.get("/") async def root(): + index_path = os.path.join("dist", "index.html") + if os.path.exists(index_path): + return FileResponse(index_path, media_type="text/html") return {"message": "边检CV算法接口服务"} @app.get("/health") @@ -47,4 +55,4 @@ async def health_check(): if __name__ == "__main__": import uvicorn - uvicorn.run(app, host="0.0.0.0", port=8000, reload=True, workers=10) \ No newline at end of file + uvicorn.run('app:app', host="0.0.0.0", port=6789, reload=True, workers=1) \ No newline at end of file