Archived
feat: 支持纯 FastAPI 模式(根路径服务前端)+ 修任务端点路径
- web/app.py:create_app(api_prefix=) 参数化前缀——'' 即根路径模式, 87 条路由直接服务前端使用的路径,无需 Flask 兜底 - web/main.py:WEB_MODE=dual(默认,迁移期)/ fastapi(纯 FastAPI)切换 - 修真实路径缺陷:任务类端点漏了 /api 段(Flask 为 /api/topen 等, 原写成 /topen),根路径模式下前端会 404。已改为 /api/topen、/api/queue、 /api/batch_progress、/api/task/*;fe_error 同步修正 - 奇偶校验路径映射同步更新 验证: - tests/test_root_mode.py 新增 66 项:前端调用的每条路径在纯 FastAPI 模式下 均非 404;root 模式不再暴露 /api/v1 - 纯 FastAPI 模式真实启动(uvicorn, PORT=5002)实测: /health、/、/static 200,/song、/api/task/list 401(鉴权生效) - 全套 pytest 135/135;ruff All checks passed;pyright 0 errors;奇偶 36/36
This commit is contained in:
1 parent
cd0f1f78a3
commit
f5d1e3c3a9
5 files changed
+107
-28
No files matched your search
+9
-3
@@ -21,10 +21,16 @@ from web.app import create_app
|
||||
|
||||
HOST = os.environ.get('HOST', '0.0.0.0')
|
||||
PORT = int(os.environ.get('PORT', '5000'))
|
||||
# 迁移期默认开启 Flask 兜底;设 FASTAPI_FLASK_FALLBACK=0 可关闭
|
||||
FLASK_FALLBACK = os.environ.get('FASTAPI_FLASK_FALLBACK', '1') == '1'
|
||||
|
||||
app = create_app(serve_flask_fallback=FLASK_FALLBACK)
|
||||
# 运行模式(默认保持迁移期形态,切换为显式操作):
|
||||
# WEB_MODE=dual(默认)已迁移路由挂 /api/v1 + Flask 兜底其余路由(前端仍走根路径→Flask)
|
||||
# WEB_MODE=fastapi 已迁移路由直接挂根路径,完全由 FastAPI 服务(不再需要 Flask)
|
||||
WEB_MODE = os.environ.get('WEB_MODE', 'dual').strip().lower()
|
||||
|
||||
if WEB_MODE == 'fastapi':
|
||||
app = create_app(serve_flask_fallback=False, api_prefix='')
|
||||
else:
|
||||
app = create_app(serve_flask_fallback=True, api_prefix='/api/v1')
|
||||
|
||||
if __name__ == '__main__':
|
||||
uvicorn.run(
|
||||
|
||||
Reference in new issue
Block a user