Cache HTML5 static assets
This commit is contained in:
@@ -135,7 +135,16 @@ from ui_semantics import form_semantics
|
||||
|
||||
app = FastAPI(title="SFERA API", version="0.1.0")
|
||||
_HTML5_ASSETS_DIR = Path(__file__).resolve().parent / "static" / "html5"
|
||||
app.mount("/html5/assets", StaticFiles(directory=_HTML5_ASSETS_DIR), name="html5-assets")
|
||||
|
||||
|
||||
class Html5StaticFiles(StaticFiles):
|
||||
def file_response(self, *args, **kwargs):
|
||||
response = super().file_response(*args, **kwargs)
|
||||
response.headers.setdefault("Cache-Control", "public, max-age=3600")
|
||||
return response
|
||||
|
||||
|
||||
app.mount("/html5/assets", Html5StaticFiles(directory=_HTML5_ASSETS_DIR), name="html5-assets")
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origin_regex=os.environ.get(
|
||||
|
||||
Reference in New Issue
Block a user