From e36c79751803b5e0bff0981e0b0368fe548784a1 Mon Sep 17 00:00:00 2001 From: Dominik Haentsch Date: Wed, 25 Oct 2023 16:08:57 +0200 Subject: [PATCH] fix: never cache frontend files --- renumics/spotlight/app.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/renumics/spotlight/app.py b/renumics/spotlight/app.py index 62220d2f..fc6993d4 100644 --- a/renumics/spotlight/app.py +++ b/renumics/spotlight/app.py @@ -15,6 +15,7 @@ from typing_extensions import Annotated from fastapi import Cookie, FastAPI, Request, status +from fastapi.datastructures import Headers from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse, Response from fastapi.staticfiles import StaticFiles @@ -56,10 +57,23 @@ from renumics.spotlight.dtypes import DTypeMap - CURRENT_LAYOUT_KEY = "layout.current" +class UncachedStaticFiles(StaticFiles): + """ + FastAPI StaticFiles but without caching + """ + + def is_not_modified( + self, response_headers: Headers, request_headers: Headers + ) -> bool: + """ + Never Cache + """ + return False + + class IssuesUpdatedMessage(Message): """ Notify about updated issues. @@ -207,9 +221,13 @@ async def _(_: Request, problem: Problem) -> JSONResponse: plugin.activate(self) try: + # Mount frontend files as uncached, + # so that we always get the new frontend after updating spotlight. + # NOTE: we might not need this if we added a version hash + # to our built js files self.mount( "/static", - StaticFiles(packages=["renumics.spotlight.backend"]), + UncachedStaticFiles(packages=["renumics.spotlight.backend"]), name="assets", ) except AssertionError: