add cache-busting query params to static assets
Generates a unique hash on app startup and appends it to all .js and .css URLs in index.html. Forces browser to fetch fresh assets on redeploy.
This commit is contained in:
parent
aa6760cb0f
commit
745b6ceea8
1 changed files with 10 additions and 3 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
"""Claude Memory API -- shared persistent memory with PostgreSQL full-text search."""
|
"""Claude Memory API -- shared persistent memory with PostgreSQL full-text search."""
|
||||||
|
|
||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import time
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from contextvars import ContextVar
|
from contextvars import ContextVar
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
@ -46,12 +48,17 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||||
app = FastAPI(title="Claude Memory API", lifespan=lifespan)
|
app = FastAPI(title="Claude Memory API", lifespan=lifespan)
|
||||||
|
|
||||||
UI_DIR = pathlib.Path(__file__).parent.parent / "ui" / "static"
|
UI_DIR = pathlib.Path(__file__).parent.parent / "ui" / "static"
|
||||||
|
_CACHE_BUST = hashlib.md5(str(time.time()).encode()).hexdigest()[:8]
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def ui_root() -> FileResponse:
|
async def ui_root() -> Response:
|
||||||
"""Serve the UI single-page app."""
|
"""Serve the UI single-page app with cache-busted static assets."""
|
||||||
return FileResponse(UI_DIR / "index.html")
|
html = (UI_DIR / "index.html").read_text()
|
||||||
|
html = html.replace("/static/js/", f"/static/js/").replace(
|
||||||
|
'.js"', f'.js?v={_CACHE_BUST}"'
|
||||||
|
).replace('.css"', f'.css?v={_CACHE_BUST}"')
|
||||||
|
return Response(content=html, media_type="text/html")
|
||||||
|
|
||||||
|
|
||||||
def _detect_sensitive(content: str) -> bool:
|
def _detect_sensitive(content: str) -> bool:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue