Skip to content

Commit b298a22

Browse files
committed
Use drupalSettings.path.baseUrl to things to work if Drupal is installed in a sub directory.
1 parent 2b2c783 commit b298a22

File tree

1 file changed

+4
-3
lines changed
  • drupal/web/themes/react_example_theme/js/src/utils

1 file changed

+4
-3
lines changed

drupal/web/themes/react_example_theme/js/src/utils/fetch.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
* Options to pass to fetch for the call to fetchUrl.
1212
*/
1313
export const fetchWithCSRFToken = (csrfUrl, fetchUrl, fetchOptions) => {
14+
1415
if (!fetchOptions.headers.get('X-CSRF-Token')) {
15-
return fetch(csrfUrl)
16+
return fetch(`${drupalSettings.path.baseUrl}${csrfUrl}`)
1617
.then(response => response.text())
1718
.then((csrfToken) => {
1819
fetchOptions.headers.append('X-CSRF-Token', csrfToken);
19-
return fetch(fetchUrl, fetchOptions);
20+
return fetch(`${drupalSettings.path.baseUrl}${fetchUrl}`, fetchOptions);
2021
});
2122
}
2223
else {
23-
return fetch(fetchUrl, fetchOptions);
24+
return fetch(`${drupalSettings.path.baseUrl}${fetchUrl}`, fetchOptions);
2425
}
2526
};

0 commit comments

Comments
 (0)