From c4f98cd6a1fd0eecb7c702c6588b007395f2d001 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Apr 2025 15:11:36 +1100 Subject: [PATCH] Report cache fix (#9447) * Adjust allowed CORS headers * Disable caching in template preview --- src/backend/InvenTree/InvenTree/settings.py | 6 ++++++ .../editors/TemplateEditor/TemplateEditor.tsx | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 2c71a9e0d9..c4a8f89ec5 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -21,6 +21,7 @@ from django.core.validators import URLValidator from django.http import Http404, HttpResponseGone import structlog +from corsheaders.defaults import default_headers as default_cors_headers from dotenv import load_dotenv from InvenTree.cache import get_cache_config, is_global_cache_enabled @@ -1203,6 +1204,11 @@ CORS_ALLOWED_ORIGIN_REGEXES = get_setting( typecast=list, ) +# Allow extra CORS headers in DEBUG mode +# Required for serving /static/ and /media/ files +if DEBUG: + CORS_ALLOW_HEADERS = (*default_cors_headers, 'cache-control', 'pragma', 'expires') + # In debug mode allow CORS requests from localhost # This allows connection from the frontend development server if DEBUG: diff --git a/src/frontend/src/components/editors/TemplateEditor/TemplateEditor.tsx b/src/frontend/src/components/editors/TemplateEditor/TemplateEditor.tsx index 218f8b5ee7..3024dc9f4c 100644 --- a/src/frontend/src/components/editors/TemplateEditor/TemplateEditor.tsx +++ b/src/frontend/src/components/editors/TemplateEditor/TemplateEditor.tsx @@ -131,8 +131,17 @@ export function TemplateEditor(props: Readonly) { api.get(templateUrl).then((response: any) => { if (response.data?.template) { + // Fetch the raw template file from the server + // Request that it is provided without any caching, + // to ensure that we always get the latest version api - .get(response.data.template) + .get(response.data.template, { + headers: { + 'Cache-Control': 'no-cache', + Pragma: 'no-cache', + Expires: '0' + } + }) .then((res) => { codeRef.current = res.data; loadCodeToEditor(res.data);