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