Replace StaticFiles with FreshStatic to disable caching for static files
Browse files- app/main.py +10 -1
app/main.py
CHANGED
|
@@ -41,13 +41,22 @@ def units_of(row: dict) -> list[str]:
|
|
| 41 |
return [unit for unit in known if unit in selected]
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def create_app(auth: SupabaseAuth | None = None) -> FastAPI:
|
| 45 |
"""Build the Mathly application."""
|
| 46 |
app = FastAPI(title="Mathly")
|
| 47 |
app.state.auth = auth or load_auth()
|
| 48 |
app.state.photo = None
|
| 49 |
app.state.photo_key = None
|
| 50 |
-
app.mount("/static",
|
| 51 |
|
| 52 |
async def signed_in(request: Request) -> dict | None:
|
| 53 |
store: SupabaseAuth | None = app.state.auth
|
|
|
|
| 41 |
return [unit for unit in known if unit in selected]
|
| 42 |
|
| 43 |
|
| 44 |
+
class FreshStatic(StaticFiles):
|
| 45 |
+
"""Static files the browser checks with the server before reusing, so a new deploy shows up on the next visit."""
|
| 46 |
+
|
| 47 |
+
async def get_response(self, path, scope):
|
| 48 |
+
response = await super().get_response(path, scope)
|
| 49 |
+
response.headers["Cache-Control"] = "no-cache"
|
| 50 |
+
return response
|
| 51 |
+
|
| 52 |
+
|
| 53 |
def create_app(auth: SupabaseAuth | None = None) -> FastAPI:
|
| 54 |
"""Build the Mathly application."""
|
| 55 |
app = FastAPI(title="Mathly")
|
| 56 |
app.state.auth = auth or load_auth()
|
| 57 |
app.state.photo = None
|
| 58 |
app.state.photo_key = None
|
| 59 |
+
app.mount("/static", FreshStatic(directory=STATIC), name="static")
|
| 60 |
|
| 61 |
async def signed_in(request: Request) -> dict | None:
|
| 62 |
store: SupabaseAuth | None = app.state.auth
|