mirror of
https://github.com/Jerryplusy/AI-powered-switches.git
synced 2025-07-04 05:09:19 +00:00
家里电脑版本:保留了连接功能
This commit is contained in:
parent
7c17bb931b
commit
71eb1ee79a
@ -1,13 +1,12 @@
|
||||
from fastapi import FastAPI, responses
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from starlette.middleware import Middleware # 新增导入
|
||||
from src.backend.app.api.endpoints import router
|
||||
from src.backend.app.utils.logger import setup_logging
|
||||
from src.backend.config import settings
|
||||
from .services.switch_traffic_monitor import get_switch_monitor
|
||||
|
||||
# 添加正确的导入
|
||||
from .services.traffic_monitor import traffic_monitor
|
||||
from src.backend.app.api.database import init_db # 修复:导入 init_db
|
||||
|
||||
from src.backend.app.api.database import init_db
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
# 初始化数据库
|
||||
@ -19,13 +18,22 @@ def create_app() -> FastAPI:
|
||||
# 设置日志
|
||||
setup_logging()
|
||||
|
||||
# 创建FastAPI应用
|
||||
# 创建FastAPI应用(使用新的中间件配置方式)
|
||||
app = FastAPI(
|
||||
title=settings.APP_NAME,
|
||||
debug=settings.DEBUG,
|
||||
docs_url=f"{settings.API_PREFIX}/docs",
|
||||
redoc_url=f"{settings.API_PREFIX}/redoc",
|
||||
openapi_url=f"{settings.API_PREFIX}/openapi.json"
|
||||
openapi_url=f"{settings.API_PREFIX}/openapi.json",
|
||||
middleware=[ # 这里直接配置中间件
|
||||
Middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
# 添加根路径重定向
|
||||
@ -33,17 +41,9 @@ def create_app() -> FastAPI:
|
||||
async def root():
|
||||
return responses.RedirectResponse(url=f"{settings.API_PREFIX}/docs")
|
||||
|
||||
# 添加favicon处理
|
||||
@app.get("/favicon.ico", include_in_schema=False)
|
||||
async def favicon():
|
||||
return responses.Response(status_code=204)
|
||||
|
||||
|
||||
# 添加API路由
|
||||
app.include_router(router, prefix=settings.API_PREFIX)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
app = create_app()
|
@ -1,3 +1,6 @@
|
||||
|
||||
import os
|
||||
os.environ["PATH"] += ";C:\\Program Files (x86)\\Nmap"
|
||||
import nmap
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
@ -1,34 +1,33 @@
|
||||
# 核心依赖
|
||||
# 核心依赖 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
fastapi==0.110.0
|
||||
uvicorn==0.29.0
|
||||
python-dotenv==1.0.1
|
||||
|
||||
# Pydantic 模型
|
||||
# Pydantic 模型 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
pydantic==2.6.4
|
||||
pydantic-settings==2.2.1
|
||||
|
||||
# 网络操作
|
||||
# 网络操作 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
asyncssh==2.14.2
|
||||
telnetlib3==2.0.3
|
||||
httpx==0.27.0
|
||||
python-nmap==0.7.1
|
||||
pysnmp==4.4.12
|
||||
|
||||
# 异步文件操作
|
||||
# 异步文件操作 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
aiofiles==23.2.1
|
||||
|
||||
# 日志管理
|
||||
# 日志管理 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
loguru==0.7.2
|
||||
|
||||
# 重试机制
|
||||
# 重试机制 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
tenacity==8.2.3
|
||||
|
||||
# 其他工具
|
||||
# 其他工具 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
asyncio==3.4.3
|
||||
typing_extensions==4.10.0
|
||||
|
||||
#监控依赖
|
||||
#监控依赖 Y
|
||||
|
||||
psutil==5.9.8
|
||||
matplotlib==3.8.3
|
||||
sqlalchemy==2.0.28
|
||||
fastapi_utils==0.2.1
|
Loading…
x
Reference in New Issue
Block a user