feat: move calculating api base url to store getter
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
kolaente 2021-10-25 22:29:21 +02:00
parent 97e761690d
commit 9a356b2564
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 6 additions and 9 deletions

View File

@ -2,6 +2,7 @@ import {CONFIG} from '../mutation-types'
import {HTTPFactory} from '@/http-common' import {HTTPFactory} from '@/http-common'
import {objectToCamelCase} from '@/helpers/case' import {objectToCamelCase} from '@/helpers/case'
import {redirectToProvider} from '../../helpers/redirectToProvider' import {redirectToProvider} from '../../helpers/redirectToProvider'
import {parseURL} from 'ufo'
export default { export default {
namespaced: true, namespaced: true,
@ -37,6 +38,10 @@ export default {
}), }),
getters: { getters: {
migratorsEnabled: state => state.availableMigrators?.length > 0, migratorsEnabled: state => state.availableMigrators?.length > 0,
apiBase(state) {
const {host, protocol} = parseURL(window.API_URL)
return protocol + '//' + host
},
}, },
mutations: { mutations: {
[CONFIG](state, config) { [CONFIG](state, config) {

View File

@ -41,15 +41,7 @@ export default {
}, },
computed: { computed: {
caldavUrl() { caldavUrl() {
let apiBase = window.API_URL.replace('/api/v1', '') return `${this.$store.getters['config/apiBase']}/dav/principals/${this.userInfo.username}/`
if (apiBase === '') { // Frontend and api on the same host which means we need to prefix the frontend url
apiBase = this.$store.state.config.frontendUrl
}
if (apiBase.endsWith('/')) {
apiBase = apiBase.substr(0, apiBase.length - 1)
}
return `${apiBase}/dav/principals/${this.userInfo.username}/`
}, },
...mapState({ ...mapState({
caldavEnabled: state => state.config.caldavEnabled, caldavEnabled: state => state.config.caldavEnabled,