Skip to content

Commit

Permalink
Merge pull request #821 from rdmorganiser/fix_management_interface
Browse files Browse the repository at this point in the history
Add support for BASE_URL to the management react interface (#815)
  • Loading branch information
jochenklar authored Nov 16, 2023
2 parents 6cc0dbd + bbccddf commit f8c4a00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions rdmo/core/assets/js/api/BaseApi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Cookies from 'js-cookie'
import isUndefined from 'lodash/isUndefined'

import baseUrl from '../utils/baseUrl'

function ApiError(statusText, status) {
this.status = status
this.statusText = statusText
Expand All @@ -16,7 +18,7 @@ function ValidationError(errors) {
class BaseApi {

static get(url) {
return fetch(url).catch(error => {
return fetch(baseUrl + url).catch(error => {
throw new ApiError(error.message)
}).then(response => {
if (response.ok) {
Expand All @@ -28,7 +30,7 @@ class BaseApi {
}

static post(url, data) {
return fetch(url, {
return fetch(baseUrl + url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -51,7 +53,7 @@ class BaseApi {
}

static put(url, data) {
return fetch(url, {
return fetch(baseUrl + url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand All @@ -74,7 +76,7 @@ class BaseApi {
}

static delete(url) {
return fetch(url, {
return fetch(baseUrl + url, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Expand All @@ -99,7 +101,7 @@ class BaseApi {
var formData = new FormData()
formData.append('file', file)

return fetch(url, {
return fetch(baseUrl + url, {
method: 'POST',
headers: {
'X-CSRFToken': Cookies.get('csrftoken')
Expand Down
2 changes: 2 additions & 0 deletions rdmo/core/assets/js/utils/baseUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// take the baseurl from the <head> of the django template
export default document.querySelector('meta[name="baseurl"]').content.replace(/\/+$/, '')
4 changes: 3 additions & 1 deletion rdmo/management/assets/js/reducers/configReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import set from 'lodash/set'

import baseUrl from 'rdmo/core/assets/js/utils/baseUrl'

const initialState = {
baseUrl: '/management/',
baseUrl: baseUrl + '/management/',
settings: {},
filter: {},
display: {}
Expand Down

0 comments on commit f8c4a00

Please sign in to comment.