export type GetApiPathArgs = {path: string}; export type GetApiPathOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Website page * * GET /{path} */ export const getApiPath = async (args: GetApiPathArgs, options?: GetApiPathOptions) => { const {baseUrl = "https://www.1global.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html") const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.path))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };