import { ofetch } from 'ofetch'

const API = import.meta.env.VITE_BACKEND

export default async (api: string, value?: any) => {
  let fetch
  try {
    if (!value) {
      fetch = await ofetch(API + api, { parseResponse: JSON.parse })
    } else {
      fetch = await ofetch(API + `${api}/${value}`, { parseResponse: JSON.parse })
    }

    return fetch
  } catch {
    return {}
  }
}
