fix build exe error

This commit is contained in:
xaoyaoo 2024-08-17 13:58:23 +08:00
parent 0c727dc34f
commit df7eecdaa4

View File

@ -24,6 +24,8 @@ from .local_server import ls_api
from pywxdump import __version__ from pywxdump import __version__
def gen_fastapi_app():
app = FastAPI(title="pywxdump", description="微信工具", version=__version__, app = FastAPI(title="pywxdump", description="微信工具", version=__version__,
terms_of_service="https://github.com/xaoyaoo/pywxdump", terms_of_service="https://github.com/xaoyaoo/pywxdump",
contact={"name": "xaoyaoo", "url": "https://github.com/xaoyaoo/pywxdump"}, contact={"name": "xaoyaoo", "url": "https://github.com/xaoyaoo/pywxdump"},
@ -45,20 +47,17 @@ app.add_middleware(
allow_headers=["*"], # 允许所有头 allow_headers=["*"], # 允许所有头
) )
@app.exception_handler(RequestValidationError) @app.exception_handler(RequestValidationError)
async def request_validation_exception_handler(request: Request, exc: RequestValidationError): async def request_validation_exception_handler(request: Request, exc: RequestValidationError):
# print(request.body) # print(request.body)
return ReJson(1002, {"detail": exc.errors()}) return ReJson(1002, {"detail": exc.errors()})
@app.get("/") @app.get("/")
@app.get("/index.html") @app.get("/index.html")
async def index(): async def index():
response = RedirectResponse(url="/s/index.html", status_code=307) response = RedirectResponse(url="/s/index.html", status_code=307)
return response return response
# 路由挂载 # 路由挂载
app.include_router(rs_api, prefix='/api/rs', tags=['远程api']) app.include_router(rs_api, prefix='/api/rs', tags=['远程api'])
app.include_router(ls_api, prefix='/api/ls', tags=['本地api']) app.include_router(ls_api, prefix='/api/ls', tags=['本地api'])
@ -68,6 +67,8 @@ web_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "ui", "web")
if os.path.exists(os.path.join(web_path, "index.html")): if os.path.exists(os.path.join(web_path, "index.html")):
app.mount("/s", StaticFiles(directory=web_path), name="static") app.mount("/s", StaticFiles(directory=web_path), name="static")
return app
def start_server(port=5000, online=False, debug=False, isopenBrowser=True): def start_server(port=5000, online=False, debug=False, isopenBrowser=True):
""" """
@ -128,8 +129,11 @@ def start_server(port=5000, online=False, debug=False, isopenBrowser=True):
time.sleep(1) time.sleep(1)
server_loger.info(f"启动flask服务host:port{host}:{port}") server_loger.info(f"启动flask服务host:port{host}:{port}")
print("[+] 请使用浏览器访问 http://127.0.0.1:5000/ 查看聊天记录") print("[+] 请使用浏览器访问 http://127.0.0.1:5000/ 查看聊天记录")
global app
app = gen_fastapi_app()
uvicorn.run(app=app, host=host, port=port, reload=debug, log_level="info", workers=1, env_file=env_file) uvicorn.run(app=app, host=host, port=port, reload=debug, log_level="info", workers=1, env_file=env_file)
__all__ = ["start_server", "app"] app = None
__all__ = ["start_server", "gen_fastapi_app"]