sepia-search-motore-di-rice.../client/src/shared/config.ts

30 lines
547 B
TypeScript

import axios from 'axios'
import { buildApiUrl } from './utils'
import { ServerConfig } from '../../../shared'
const basePath = '/api/v1/config'
let serverConfig: ServerConfig
function getConfigHttp () {
return axios.get<ServerConfig>(buildApiUrl(basePath))
}
async function loadServerConfig () {
const res = await getConfigHttp()
serverConfig = res.data
return serverConfig
}
function getConfig () {
if (serverConfig) return Promise.resolve(serverConfig)
return loadServerConfig()
}
export {
getConfig,
loadServerConfig
}