19 lines
610 B
TypeScript
19 lines
610 B
TypeScript
export async function apiFetch<T>(path: string) {
|
|
const config = useRuntimeConfig()
|
|
const apiBase = config.public.apiBase
|
|
const headers = new Headers()
|
|
headers.set('Referer', config.public.baseUrl)
|
|
return useFetch<T>(`${apiBase}/${path}`, {
|
|
baseURL: config.public.baseUrl,
|
|
headers,
|
|
onResponseError({ response }) {
|
|
console.log(response.status)
|
|
console.log(response.url)
|
|
window.location.pathname = '/404'
|
|
throw createError({
|
|
statusCode: 404,
|
|
fatal: true
|
|
})
|
|
},
|
|
})
|
|
} |