fix 修改flask启动方式

This commit is contained in:
xaoyaoo 2024-12-29 02:03:21 +08:00
parent 6a3d0797fb
commit fcab5ad5e1

View File

@ -29,7 +29,7 @@ from .local_server import ls_api
from pywxdump import __version__
def gen_fastapi_app(handler):
def gen_fastapi_app(handler, origins=None):
app = FastAPI(title="wxdump", description="微信工具", version=__version__,
terms_of_service="https://github.com/xaoyaoo/pywxdump",
contact={"name": "xaoyaoo", "url": "https://github.com/xaoyaoo/pywxdump"},
@ -37,15 +37,15 @@ def gen_fastapi_app(handler):
"url": "https://github.com/xaoyaoo/PyWxDump/blob/master/LICENSE"})
web_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "ui", "web") # web文件夹路径
# 跨域
origins = [
"http://localhost:5000",
"http://127.0.0.1:5000",
"http://localhost:8080", # 开发环境的客户端地址"
# "http://0.0.0.0:5000",
# "*"
]
if not origins:
origins = [
"http://localhost:5000",
"http://127.0.0.1:5000",
"http://localhost:8080", # 开发环境的客户端地址"
# "http://0.0.0.0:5000",
# "*"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins, # 允许所有源
@ -191,10 +191,17 @@ def start_server(port=5000, online=False, debug=False, isopenBrowser=True,
time.sleep(1)
server_loger.info(f"启动flask服务host:port{host}:{port}")
print("[+] 请使用浏览器访问 http://127.0.0.1:5000/ 查看聊天记录")
print(f"[+] 请使用浏览器访问 http://127.0.0.1:{port}/ 查看聊天记录")
global app
print("[+] 如需查看api文档请访问 http://127.0.0.1:5000/docs ")
app = gen_fastapi_app(file_handler)
print(f"[+] 如需查看api文档请访问 http://127.0.0.1:{port}/docs ")
origins = [
f"http://localhost:{port}",
f"http://{host}:{port}",
f"http://localhost:8080", # 开发环境的客户端地址"
# f"http://0.0.0.0:{port}",
# "*"
]
app = gen_fastapi_app(file_handler, origins)
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "[%(asctime)s] %(levelprefix)s %(message)s"
LOGGING_CONFIG["formatters"]["access"][