Spaces:
Running
Running
Serve the page uncached with versioned assets so embeds pick up new builds
Browse files- app/main.py +13 -1
app/main.py
CHANGED
|
@@ -264,9 +264,21 @@ from curate_api import router as curate_router # noqa: E402 (imports make_endp
|
|
| 264 |
app.include_router(curate_router)
|
| 265 |
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
@app.get("/")
|
| 268 |
def index():
|
| 269 |
-
|
|
|
|
| 270 |
|
| 271 |
|
| 272 |
app.mount("/static", StaticFiles(directory=STATIC), name="static")
|
|
|
|
| 264 |
app.include_router(curate_router)
|
| 265 |
|
| 266 |
|
| 267 |
+
def _asset_version() -> str:
|
| 268 |
+
import hashlib
|
| 269 |
+
h = hashlib.sha1()
|
| 270 |
+
for f in ("app.js", "curate.js", "app.css"):
|
| 271 |
+
h.update((STATIC / f).read_bytes())
|
| 272 |
+
return h.hexdigest()[:10]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
INDEX_HTML = (STATIC / "index.html").read_text().replace(".js\"", f".js?v={_asset_version()}\"").replace(".css\"", f".css?v={_asset_version()}\"")
|
| 276 |
+
|
| 277 |
+
|
| 278 |
@app.get("/")
|
| 279 |
def index():
|
| 280 |
+
# never cache the page itself (embeds kept showing an old build); assets carry a content hash instead
|
| 281 |
+
return Response(INDEX_HTML, media_type="text/html", headers={"Cache-Control": "no-cache"})
|
| 282 |
|
| 283 |
|
| 284 |
app.mount("/static", StaticFiles(directory=STATIC), name="static")
|