diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 198c945e3b..c7745bb828 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -21,6 +21,7 @@ from django.http import Http404 import pytz 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 @@ -1290,6 +1291,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 b01bdafd79..04390390a7 100644 --- a/src/frontend/src/components/editors/TemplateEditor/TemplateEditor.tsx +++ b/src/frontend/src/components/editors/TemplateEditor/TemplateEditor.tsx @@ -132,8 +132,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);