Spaces:
Paused
Paused
CI deploy ad5ff8be
Browse files- server/main.py +9 -2
- static/assets/index-BZ_QKopz.js +0 -0
- static/index.html +1 -1
- tests/test_api.py +14 -0
server/main.py
CHANGED
|
@@ -232,9 +232,16 @@ def _error_stream(message: str) -> StreamingResponse:
|
|
| 232 |
if STATIC.is_dir():
|
| 233 |
app.mount("/assets", StaticFiles(directory=STATIC / "assets"), name="assets")
|
| 234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
@app.get("/")
|
| 236 |
async def index():
|
| 237 |
-
return FileResponse(STATIC / "index.html")
|
| 238 |
|
| 239 |
@app.get("/{path:path}")
|
| 240 |
async def spa(path: str):
|
|
@@ -248,4 +255,4 @@ if STATIC.is_dir():
|
|
| 248 |
target = STATIC / path
|
| 249 |
if target.is_file():
|
| 250 |
return FileResponse(target)
|
| 251 |
-
return FileResponse(STATIC / "index.html")
|
|
|
|
| 232 |
if STATIC.is_dir():
|
| 233 |
app.mount("/assets", StaticFiles(directory=STATIC / "assets"), name="assets")
|
| 234 |
|
| 235 |
+
# The bundle's filename carries a content hash, so `index.html` is the only
|
| 236 |
+
# thing that has to be re-fetched for a deploy to be visible. Cached, it
|
| 237 |
+
# keeps pointing at the previous bundle for as long as the browser feels
|
| 238 |
+
# like it -- which reads as "the deploy did nothing", and cost an afternoon
|
| 239 |
+
# of testing against a build that was no longer there.
|
| 240 |
+
NO_CACHE = {"Cache-Control": "no-cache, must-revalidate"}
|
| 241 |
+
|
| 242 |
@app.get("/")
|
| 243 |
async def index():
|
| 244 |
+
return FileResponse(STATIC / "index.html", headers=NO_CACHE)
|
| 245 |
|
| 246 |
@app.get("/{path:path}")
|
| 247 |
async def spa(path: str):
|
|
|
|
| 255 |
target = STATIC / path
|
| 256 |
if target.is_file():
|
| 257 |
return FileResponse(target)
|
| 258 |
+
return FileResponse(STATIC / "index.html", headers=NO_CACHE)
|
static/assets/index-BZ_QKopz.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
static/index.html
CHANGED
|
@@ -18,7 +18,7 @@
|
|
| 18 |
font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: #c9a227;
|
| 19 |
}
|
| 20 |
</style>
|
| 21 |
-
<script type="module" crossorigin src="./assets/index-
|
| 22 |
</head>
|
| 23 |
<body>
|
| 24 |
<div id="app"></div>
|
|
|
|
| 18 |
font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: #c9a227;
|
| 19 |
}
|
| 20 |
</style>
|
| 21 |
+
<script type="module" crossorigin src="./assets/index-BZ_QKopz.js"></script>
|
| 22 |
</head>
|
| 23 |
<body>
|
| 24 |
<div id="app"></div>
|
tests/test_api.py
CHANGED
|
@@ -110,3 +110,17 @@ def test_a_non_api_path_still_falls_through_to_the_app(client):
|
|
| 110 |
# bare checkout, since CI builds it before the deploy either way.
|
| 111 |
r = client.get("/some/client/route")
|
| 112 |
assert r.status_code in (200, 404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
# bare checkout, since CI builds it before the deploy either way.
|
| 111 |
r = client.get("/some/client/route")
|
| 112 |
assert r.status_code in (200, 404)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def test_the_page_is_not_cached(client):
|
| 116 |
+
"""A cached index.html keeps pointing at the previous bundle.
|
| 117 |
+
|
| 118 |
+
The assets are content-hashed and may cache forever; the page that names
|
| 119 |
+
them may not, or a deploy is invisible until the browser feels like
|
| 120 |
+
re-fetching — which reads as "the deploy did nothing".
|
| 121 |
+
"""
|
| 122 |
+
for path in ("/", "/anything"):
|
| 123 |
+
r = client.get(path)
|
| 124 |
+
if r.status_code != 200:
|
| 125 |
+
continue
|
| 126 |
+
assert "no-cache" in r.headers.get("cache-control", "")
|