This repository has been archived on 2026-10-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
NeteaseUrl/web/routers/index.py
T
snowy-yang 064a89d726 refactor: 删除旧前端单体,React 产物成为唯一首页来源
为什么:React 迁移已验证完毕(浏览器冒烟全过、golden 刷新),
legacy 模板兜底分支指向已删除的文件只会制造幻觉路径。删除
templates/index.html(466KB)与 static/site_auth.js(80KB)及
/static 挂载;jinja2 随兜底分支失去唯一使用者,连同 markupsafe
一并移出依赖(63 包 -2)。_render_index 简化为直接读构建产物——
dist 已入库恒存在,无需分支。
2026-09-27 18:41:30 +08:00

31 lines
1006 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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'},
)