2026-10-01 20:36:06 +03:30
|
|
|
import type { NitroFetchOptions, NitroFetchRequest } from "nitropack";
|
|
|
|
|
|
|
|
|
|
/** SSR talks to the API directly; the browser uses same-origin `/api` (nginx in production, devProxy locally). */
|
|
|
|
|
export function useApiBase(): string {
|
2026-09-30 18:42:28 +03:30
|
|
|
const config = useRuntimeConfig();
|
2026-10-01 20:36:06 +03:30
|
|
|
if (import.meta.server) return config.apiBase;
|
|
|
|
|
return config.public.apiBase || "";
|
2026-09-30 18:42:28 +03:30
|
|
|
}
|
|
|
|
|
|
2026-10-01 20:36:06 +03:30
|
|
|
export function apiFetch<T>(path: string, options?: NitroFetchOptions<NitroFetchRequest>): Promise<T> {
|
|
|
|
|
return $fetch<T>(`${useApiBase()}${path}`, options as never) as Promise<T>;
|
2026-09-30 18:42:28 +03:30
|
|
|
}
|