Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: never cache frontend files #310

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading