Skip to content

Commit

Permalink
Disable caching of index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
votdev committed Sep 29, 2023
1 parent 55612ff commit 025ae6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/frontend/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="apple-touch-icon" href="favicon_180x180.png">
<link rel="icon" href="favicon.svg" sizes="any" type="image/svg+xml">
Expand Down
21 changes: 19 additions & 2 deletions src/s3gw_ui_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,30 @@
from typing import Awaitable, Callable

import uvicorn
from fastapi import FastAPI
from fastapi import FastAPI, Response
from fastapi.logger import logger
from fastapi.staticfiles import StaticFiles
from starlette.types import Scope

from backend.api import admin, auth, buckets, config, objects
from backend.config import Config
from backend.logging import setup_logging


class S3gwStaticFiles(StaticFiles):
async def get_response(self, path: str, scope: Scope) -> Response:
resp = await super().get_response(path, scope)
if scope["path"] == "/": # index.html
resp.headers.update(
{
"Cache-Control": "no-cache, max-age=0, must-revalidate",
"Expires": "0",
"Pragma": "no-cache",
}
)
return resp


async def s3gw_startup(s3gw_app: FastAPI, s3gw_api: FastAPI) -> None:
setup_logging()
logger.info("Starting s3gw-ui backend")
Expand Down Expand Up @@ -90,7 +105,9 @@ async def on_shutdown(): # type: ignore
s3gw_app.mount("/api", s3gw_api, name="api")
if static_dir is not None:
s3gw_app.mount(
"/", StaticFiles(directory=static_dir, html=True), name="static"
"/",
S3gwStaticFiles(directory=static_dir, html=True),
name="static",
)

return s3gw_app
Expand Down

0 comments on commit 025ae6f

Please sign in to comment.