Add BaseURL configuration (fixes #103)
This commit is contained in:
@@ -34,6 +34,7 @@ const App = () => {
|
||||
if (appConfig.firstTime) {
|
||||
localStorage.setItem('initialAccountCreation', 'true')
|
||||
}
|
||||
localStorage.setItem('baseURL', appConfig.baseURL)
|
||||
} catch (e) {}
|
||||
|
||||
return (
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user