Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BASE_URL to the management react interface (#815) #821

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 rdmoBaseUrl from 'rdmo/core/assets/js/utils/baseUrl'

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