Made Changes To Allow The Base API URL To Be From Config

This commit is contained in:
Annika Merris 2024-02-05 21:56:07 -05:00
parent 823455cf78
commit baf8e0f954
6 changed files with 44 additions and 57 deletions

View file

@ -12,12 +12,13 @@ import '@mdi/font/css/materialdesignicons.css'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import axios from 'axios'
const vuetify = createVuetify({
components,
directives,
icons: {
defaultSet: 'mdi',
defaultSet: 'mdi'
},
theme: {
defaultTheme: 'dark'
@ -25,9 +26,19 @@ const vuetify = createVuetify({
})
const app = createApp(App)
app.use(createPinia())
const pinia = createPinia()
app.use(pinia)
app.use(router)
app.use(vuetify)
app.mount('#app')
// Fetch my config
axios
.get('/config.json?noCache=' + Date.now())
.then((resp) => {
app.config.globalProperties.$apiBaseUrl = resp.data.apiBaseUrl
app.mount('#app')
})
.catch((err) => {
console.log(err)
})

View file

@ -1,7 +1,22 @@
import type { PowerItem } from '@/types/PowerItem'
import axios from 'axios'
import axios, { type AxiosRequestConfig } from 'axios'
import { defineStore } from 'pinia'
import { computed, ref, toRaw } from 'vue'
import axiosRetry from 'axios-retry'
import { getCurrentInstance } from 'vue'
const BLESSING = 1
const INTIMACY = 2
const FELLOW = 3
const noCacheConfig:AxiosRequestConfig = {
responseType: "json",
headers: {
'Cache-Control': 'no-cache',
'Pragma': 'no-cache',
'Expires': '0',
}
}
export const usePowerItems = defineStore('powerItems', () => {
const BLESSING_POWER_ITEM_STORAGE = 'BLESSING_POWER_ITEM_STORAGE'
@ -11,16 +26,16 @@ export const usePowerItems = defineStore('powerItems', () => {
const fellowPowerItems = ref(new Map<string, PowerItem>())
const intimacyPowerItems = ref(new Map<string, PowerItem>())
const isLoadComplete = ref(false)
const apiBaseUrl = getCurrentInstance()?.appContext.config.globalProperties.$apiBaseUrl
axiosRetry(axios, {
retries: 3,
retryDelay: axiosRetry.exponentialDelay,
})
async function fetchPowerItems() {
axios
.get('/items/blessingPowerItems.json', {
headers: {
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0'
}
})
.get(apiBaseUrl + '/powerItem/byType/' + BLESSING + '/asMap', noCacheConfig)
.then((resp) => {
const plainMap = new Map<string, PowerItem>(
Object.entries(JSON.parse(localStorage.getItem(BLESSING_POWER_ITEM_STORAGE) || '{}'))
@ -36,13 +51,7 @@ export const usePowerItems = defineStore('powerItems', () => {
console.log(err)
})
axios
.get('/items/fellowPowerItems.json', {
headers: {
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0'
}
})
.get(apiBaseUrl + '/powerItem/byType/' + FELLOW + '/asMap', noCacheConfig)
.then((resp) => {
const plainMap = new Map<string, PowerItem>(
Object.entries(JSON.parse(localStorage.getItem(FELLOW_POWER_ITEM_STORAGE) || '{}'))
@ -58,13 +67,7 @@ export const usePowerItems = defineStore('powerItems', () => {
console.log(err)
})
axios
.get('/items/intimacyPowerItems.json', {
headers: {
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0'
}
})
.get(apiBaseUrl + '/powerItem/byType/' + INTIMACY + '/asMap', noCacheConfig)
.then((resp) => {
const plainMap = new Map<string, PowerItem>(
Object.entries(JSON.parse(localStorage.getItem(INTIMACY_POWER_ITEM_STORAGE) || '{}'))