# -*- coding: utf-8 -*- """首页。 - GET / 首页:服务 React 构建产物 frontend/dist/index.html (vite 固定产物文件名,字节级稳定,golden 契约依赖此点) - 构建产物经 /assets 挂载(见 web/app.py) """ from pathlib import Path from fastapi import APIRouter, Request from fastapi.responses import HTMLResponse router = APIRouter() _PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent _DIST_INDEX = _PROJECT_ROOT / 'frontend' / 'dist' / 'index.html' def _render_index() -> str: """返回 React 构建产物原样字节(构建产物入库,恒存在)。""" return _DIST_INDEX.read_text(encoding='utf-8') @router.get('/', response_class=HTMLResponse) async def index(request: Request) -> HTMLResponse: """首页(禁止缓存,确保前端更新即时生效)。""" return HTMLResponse( content=_render_index(), headers={'Cache-Control': 'no-cache, no-store, must-revalidate'}, )