All files / munch-ease-frontend/src/api client.ts

100% Statements 20/20
25% Branches 1/4
100% Functions 1/1
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 20x 1x  
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<paths>({
  baseUrl,
  fetch: (input: RequestInfo | URL, init?: RequestInit) => {
    return globalThis.fetch(input, {
      credentials: 'include',
      ...init,
    })
  },
})