2026-05-28 13:52:15 -05:00
|
|
|
import createClient from "openapi-fetch";
|
|
|
|
|
import type { Instance } from "@/lib/config";
|
2026-06-02 11:47:24 -05:00
|
|
|
import { dispatchFor } from "@/lib/dispatch";
|
2026-05-28 13:52:15 -05:00
|
|
|
import type { paths } from "./schema.d.ts";
|
|
|
|
|
|
|
|
|
|
export type ScopedClient = ReturnType<typeof createClient<paths>>;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-06-02 11:47:24 -05:00
|
|
|
* Create an openapi-fetch client bound to a specific instance. Use for views that
|
|
|
|
|
* query non-active instances (e.g. the Fleet side-by-side comparison). Each scoped
|
|
|
|
|
* client self-routes via its own X-Honcho-Upstream header in web mode.
|
2026-05-28 13:52:15 -05:00
|
|
|
*/
|
|
|
|
|
export function createScopedClient(instance: Instance): ScopedClient {
|
2026-06-02 11:47:24 -05:00
|
|
|
const { baseUrl, headers, fetch } = dispatchFor(instance);
|
|
|
|
|
return createClient<paths>({ baseUrl, headers, fetch });
|
2026-05-28 13:52:15 -05:00
|
|
|
}
|