Archived
feat: 后端接线上 React 构建产物,legacy 模板降级为兜底
为什么:前端迁移到 Vite 后,首页应直接返回 frontend/dist/index.html 字节(golden 口径随之变为构建产物原样字节),仅当 dist 未构建时 回退 Jinja2 渲染的 legacy 模板。同步挂载 /assets 静态目录、排除 frontend 的 node_modules/tsbuildinfo 入库、docker 构建只带 dist 不带源码、ruff/pyright 排除 frontend 目录(TS 侧由 tsc+vite 把关)。
This commit is contained in:
1 parent
3a089caff2
commit
8803444755
5 files changed
+44
-18
No files matched your search
@@ -114,6 +114,15 @@ def create_app(api_prefix: str = '', *, start_monitor: bool = True) -> FastAPI:
|
||||
if _static_dir.is_dir():
|
||||
app.mount('/static', StaticFiles(directory=str(_static_dir)), name='static')
|
||||
|
||||
# React 构建产物(vite build → frontend/dist,hash 指纹资源挂 /assets)
|
||||
_dist_dir = Path(__file__).resolve().parent.parent / 'frontend' / 'dist'
|
||||
if (_dist_dir / 'assets').is_dir():
|
||||
app.mount(
|
||||
'/assets',
|
||||
StaticFiles(directory=str(_dist_dir / 'assets')),
|
||||
name='assets',
|
||||
)
|
||||
|
||||
# 业务路由:统一挂到 api_prefix(默认空前缀,即前端使用的根路径)
|
||||
app.include_router(system_router.router, prefix=api_prefix, tags=['system'])
|
||||
app.include_router(site_router.router, prefix=api_prefix, tags=['site'])
|
||||
|
||||
Reference in new issue
Block a user