Add a config object to hold values like API hosts, instead of hard coding it to my local machine's name.

Make sure the file exists before trying to read it.
This commit is contained in:
Daniel Ceregatti 2023-09-11 17:26:16 -07:00
parent 4c3823d9bc
commit 07eb8ac7ff
5 changed files with 11 additions and 6 deletions

View file

@ -5,7 +5,8 @@ import Servers from '@/components/Servers.vue'
import { useFetch } from '@vueuse/core'
import { useAppStore } from '@/stores/app.js'
const store = useAppStore()
const { error, data } = await useFetch('http://bubba:8000/status').get().json()
import { config } from '@/config'
const { error, data } = await useFetch(config.baseUrl + '/status').get().json()
const set = (w, e) => {
store.section = w
const active = Array.from(document.getElementsByClassName('active'))

View file

@ -3,7 +3,8 @@ import { useFetch } from "@vueuse/core"
import xmlTree from '@/components/XmlTree.vue'
import { useAppStore } from '@/stores/app.js'
const store = useAppStore()
const { data, error } = useFetch(() => `http://bubba:8000/mod/${store.modId}`, {
import { config } from '@/config'
const { data, error } = useFetch(() => config.baseUrl + `/mod/${store.modId}`, {
immediate: false,
refetch: true
}).get().json()

View file

@ -4,7 +4,7 @@ import { BKMG } from '@/util'
import { useFetch} from '@vueuse/core'
import { useAppStore } from '@/stores/app.js'
const store = useAppStore()
const { data: searchResults, error, isFetching } = useFetch(() => `http://bubba:8000/search/${store.searchText}`, {
const { data: searchResults, error, isFetching } = useFetch(() => config.baseUrl + `/search/${store.searchText}`, {
immediate: false,
refetch: true,
afterFetch(response) {

View file

@ -46,6 +46,7 @@
<script>
import { useFetch } from '@vueuse/core'
import { config } from '@/config'
export default {
name: "xmlTree",
props: {
@ -85,7 +86,7 @@ export default {
if (this.element) {
return this.element
} else if(this.file) {
const { data } = await useFetch(`http://bubba:8000/mod/${this.modId}/${this.file}`)
const { data } = await useFetch(config.baseUrl + `/mod/${this.modId}/${this.file}`)
const parser = new DOMParser()
const xmlDoc = parser.parseFromString(data, "text/xml")
return xmlDoc.documentElement

View file

@ -215,8 +215,10 @@ app.get('/mod/:modId', (req, res) => {
app.get('/mod/:modId/:file', (req, res) => {
const modId = req.params["modId"]
const file = req.params["file"]
if (fs.existsSync(config.modDir + d + modId + d + file)) {
const contents = fs.readFileSync(config.modDir + d + modId + d + file)
res.send(contents)
}
})
// Search for a mod