INNER CODE UNIT · Python
SPAShellNoCacheMiddleware
ArcReel/ArcReel · server/app.py:736
class SPAShellNoCacheMiddleware:
"""SPA 入口 HTML 外壳禁止浏览器缓存。
覆盖 spa_deep_link 与 app.frontend 原生 fallback 两条路径共用的响应特征
(text/html),否则重新部署后浏览器可能沿用旧壳加载已被删除的旧哈希资源,
导致白屏——按 content-type 而非按路由判定,才能同时管住 "/"、"/login" 等
落在原生 fallback 上的入口。纯 ASGI 实现而非 BaseHTTPMiddleware:这是个作用于
全部请求的全局中间件,BaseHTTPMiddleware 的 anyio TaskGroup + contextvars
复制机制会给每个请求引入额外开销。
"""
def __init__(self, app):
self.app = app
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] != "http":
await self.app(scope, receive, send)
return