2026-04-27 11:20:47 -05:00
|
|
|
import createClient from "openapi-fetch";
|
2026-04-24 16:52:40 -05:00
|
|
|
import { loadConfig } from "@/lib/config";
|
|
|
|
|
import { httpFetch } from "@/lib/http";
|
2026-04-24 21:30:48 -05:00
|
|
|
import type { paths } from "./schema.d.ts";
|
|
|
|
|
|
|
|
|
|
export function createHonchoClient() {
|
|
|
|
|
const config = loadConfig();
|
|
|
|
|
const baseUrl = config?.baseUrl ?? "http://localhost:8000";
|
|
|
|
|
const token = config?.token ?? "";
|
|
|
|
|
|
|
|
|
|
const headers: Record<string, string> = {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
if (token) {
|
2026-04-24 16:52:40 -05:00
|
|
|
headers.Authorization = `Bearer ${token}`;
|
2026-04-24 21:30:48 -05:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 16:52:40 -05:00
|
|
|
return createClient<paths>({ baseUrl, headers, fetch: httpFetch });
|
2026-04-24 21:30:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const client = {
|
|
|
|
|
get current() {
|
|
|
|
|
return createHonchoClient();
|
|
|
|
|
},
|
|
|
|
|
};
|