import { conf } from "@/setup/config"; import { ofetch } from "ofetch"; type P = Parameters>; type R = ReturnType>; const baseFetch = ofetch.create({ retry: 0, }); export function makeUrl(url: string, data: Record) { let parsedUrl: string = url; Object.entries(data).forEach(([k, v]) => { parsedUrl = parsedUrl.replace(`{${k}}`, encodeURIComponent(v)); }); return parsedUrl; } export function mwFetch(url: string, ops: P[1]): R { return baseFetch(url, ops); } export function proxiedFetch(url: string, ops: P[1]): R { const parsedUrl = new URL(url); Object.entries(ops?.params ?? {}).forEach(([k, v]) => { parsedUrl.searchParams.set(k, v); }); return baseFetch(conf().BASE_PROXY_URL, { ...ops, baseURL: undefined, params: { destination: parsedUrl.toString(), }, }); }