import { useRuntimeConfig, useFetch, createError } from '#imports' export function useApiFetch() { const config = useRuntimeConfig() const apiBase = config.public.apiBase const prefix = config.public.apiPrefix const fetchData = (path: string, queryParams: Record = {}, global = false) => { const headers = new Headers() headers.set('Referer', config.public.baseUrl) return useFetch(`${apiBase}/${global ? 'gb' : prefix}/${path}/`, { baseURL: config.public.baseUrl, headers, query: queryParams, onResponseError({ response }) { console.log(response.status) console.log(response.url) window.location.pathname = '/404' throw createError({ statusCode: 404, fatal: true }) }, }) } return { fetchData } }