Add BaseURL configuration (fixes #103)

This commit is contained in:
Deluan
2020-04-03 17:50:42 -04:00
parent b8eb22d162
commit 75cd21da1f
17 changed files with 61 additions and 25 deletions
+1
View File
@@ -34,6 +34,7 @@ const App = () => {
if (appConfig.firstTime) {
localStorage.setItem('initialAccountCreation', 'true')
}
localStorage.setItem('baseURL', appConfig.baseURL)
} catch (e) {}
return (
+3 -2
View File
@@ -1,11 +1,12 @@
import jwtDecode from 'jwt-decode'
import md5 from 'md5-hex'
import baseUrl from './utils/baseUrl'
const authProvider = {
login: ({ username, password }) => {
let url = '/app/login'
let url = baseUrl('/app/login')
if (localStorage.getItem('initialAccountCreation')) {
url = '/app/createAdmin'
url = baseUrl('/app/createAdmin')
}
const request = new Request(url, {
method: 'POST',
+5 -3
View File
@@ -1,10 +1,12 @@
import { fetchUtils } from 'react-admin'
import jsonServerProvider from 'ra-data-json-server'
import baseUrl from './utils/baseUrl'
const baseUrl = '/app/api'
const restUrl = '/app/api'
const httpClient = (url, options = {}) => {
url = url.replace(baseUrl + '/albumSong', baseUrl + '/song')
url = baseUrl(url)
url = url.replace(restUrl + '/albumSong', restUrl + '/song')
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' })
}
@@ -22,6 +24,6 @@ const httpClient = (url, options = {}) => {
})
}
const dataProvider = jsonServerProvider(baseUrl, httpClient)
const dataProvider = jsonServerProvider(restUrl, httpClient)
export default dataProvider
+3 -1
View File
@@ -1,4 +1,5 @@
import { fetchUtils } from 'react-admin'
import baseUrl from "../utils/baseUrl"
const url = (command, id, options) => {
const params = new URLSearchParams()
@@ -18,7 +19,8 @@ const url = (command, id, options) => {
params.append(k, options[k])
})
}
return `rest/${command}?${params.toString()}`
const url = `/rest/${command}?${params.toString()}`
return baseUrl(url)
}
const scrobble = (id, submit) => {
+8
View File
@@ -0,0 +1,8 @@
const baseUrl = (path) => {
const base = localStorage.getItem('baseURL') || ''
const parts = [base]
parts.push(path.replace(/^\//, ''))
return parts.join('/')
}
export default baseUrl