Skip to content

Commit

Permalink
fix: never cache frontend files
Browse files Browse the repository at this point in the history
  • Loading branch information
neindochoh committed Oct 25, 2023
1 parent ec914f5 commit e36c797
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions renumics/spotlight/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e36c797

Please sign in to comment.