feat 支持直接响应前端页面
This commit is contained in:
parent
85175e60a5
commit
2fdfd63370
91
server/.gitignore
vendored
Normal file
91
server/.gitignore
vendored
Normal file
@ -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
|
@ -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)
|
||||
uvicorn.run('app:app', host="0.0.0.0", port=6789, reload=True, workers=1)
|
Loading…
x
Reference in New Issue
Block a user