Use CSRF_HEADER_NAME from global config for preview panel DELETE request

pull/9650/head
Sage Abdullah 2022-11-09 09:42:06 +00:00 zatwierdzone przez Matt Westcott
rodzic a4ec6afae5
commit ff8a33733c
1 zmienionych plików z 4 dodań i 8 usunięć

Wyświetl plik

@ -1,3 +1,4 @@
import { WAGTAIL_CONFIG } from '../../config/wagtailConfig';
import { gettext } from '../../utils/gettext';
function initPreview() {
@ -143,16 +144,11 @@ function initPreview() {
newIframe.addEventListener('load', handleLoad);
};
const clearPreviewData = () => {
const csrfToken = document.querySelector(
'input[name="csrfmiddlewaretoken"]',
).value;
return fetch(previewUrl, {
headers: { 'X-CSRFToken': csrfToken },
const clearPreviewData = () =>
fetch(previewUrl, {
headers: { [WAGTAIL_CONFIG.CSRF_HEADER_NAME]: WAGTAIL_CONFIG.CSRF_TOKEN },
method: 'DELETE',
});
};
const setPreviewData = () => {
// Bail out if there is already a pending update