turn apiEndpoint into composable to avoid nuxt context errors

This commit is contained in:
axolotle 2023-09-04 16:36:42 +02:00
parent 535dd0e0c5
commit 46a76ff4bc

View file

@ -1,11 +1,14 @@
import type { FetchError } from 'ofetch'
const apiEndpoint =
'https://' +
(process.dev
? useRuntimeConfig().public.apiIp || window.location.hostname
: window.location.hostname) +
'/yunohost/portalapi'
const useApiEndpoint = () => {
return (
'https://' +
(process.dev
? useRuntimeConfig().public.apiIp || window.location.hostname
: window.location.hostname) +
'/yunohost/portalapi'
)
}
export function useApi<T>(
path: string,
@ -27,7 +30,7 @@ export function useApi<T>(
}
const query = () => {
return $fetch(apiEndpoint + path, {
return $fetch(useApiEndpoint() + path, {
method,
credentials: 'include',
body,