/** * Központi API composable * Az összes API hívás ezen keresztül történik */ export const useApi = () => { const config = useRuntimeConfig() const baseUrl = config.public.apiBase as string /** * API végpont URL összeállítása */ const getUrl = (endpoint: string): string => { // Ha már teljes URL, visszaadjuk if (endpoint.startsWith('http')) { return endpoint } // Biztosítjuk, hogy az endpoint /-vel kezdődjön const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}` return `${baseUrl}${path}` } /** * useFetch wrapper az API hívásokhoz */ const apiFetch = (endpoint: string, options?: Parameters[1]) => { return useFetch(getUrl(endpoint), options) } /** * $fetch wrapper az API hívásokhoz (nem reaktív, közvetlen hívás) */ const apiRequest = (endpoint: string, options?: Parameters[1]) => { return $fetch(getUrl(endpoint), options) } return { baseUrl, getUrl, apiFetch, apiRequest } }