import createClient from 'openapi-fetch' import type { paths } from './types' // Vue CLI uses process.env.VUE_APP_* const vueCliBase: string | undefined = typeof process !== 'undefined' ? (process.env?.VUE_APP_API_BASE ?? undefined) : undefined const isTest = typeof process !== 'undefined' && (process.env?.VITEST === 'true' || process.env?.NODE_ENV === 'test') // Prefer absolute http URL in tests to avoid TLS issues and ease MSW interception // Use host-only base URL; always pass full "/api/v1/..." paths to the client methods const defaultBase = '' const baseUrl: string = isTest ? 'http://localhost' : (vueCliBase || defaultBase) export const api = createClient({ baseUrl, fetch: (input: RequestInfo | URL, init?: RequestInit) => { return globalThis.fetch(input, { credentials: 'include', ...init, }) }, })