From 46a76ff4bc0142e73dc6a73d15e59ff766ee5973 Mon Sep 17 00:00:00 2001 From: axolotle Date: Mon, 4 Sep 2023 16:36:42 +0200 Subject: [PATCH] turn apiEndpoint into composable to avoid nuxt context errors --- composables/api.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/composables/api.ts b/composables/api.ts index f7ce12d..d5cf56a 100644 --- a/composables/api.ts +++ b/composables/api.ts @@ -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( path: string, @@ -27,7 +30,7 @@ export function useApi( } const query = () => { - return $fetch(apiEndpoint + path, { + return $fetch(useApiEndpoint() + path, { method, credentials: 'include', body,