feat(web): route web build through same-origin /api proxy
client.current and createScopedClient resolve transport via dispatchFor: web -> absolute origin + /api base with an X-Honcho-Upstream header; Tauri -> absolute instance URL + reqwest. Absolute base (not bare "/api") so openapi-fetch can construct a Request under node/undici and in the browser alike. Fleet fan-out is unchanged; fleet.test.tsx now asserts the proxy contract.
This commit is contained in:
@@ -1,21 +1,12 @@
|
||||
import createClient from "openapi-fetch";
|
||||
import { loadConfig } from "@/lib/config";
|
||||
import { httpFetch } from "@/lib/http";
|
||||
import { dispatchFor } from "@/lib/dispatch";
|
||||
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) {
|
||||
headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
return createClient<paths>({ baseUrl, headers, fetch: httpFetch });
|
||||
const config = loadConfig() ?? { baseUrl: "http://localhost:8000", token: "" };
|
||||
const { baseUrl, headers, fetch } = dispatchFor(config);
|
||||
return createClient<paths>({ baseUrl, headers, fetch });
|
||||
}
|
||||
|
||||
export const client = {
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import createClient from "openapi-fetch";
|
||||
import type { Instance } from "@/lib/config";
|
||||
import { httpFetch } from "@/lib/http";
|
||||
import { dispatchFor } from "@/lib/dispatch";
|
||||
import type { paths } from "./schema.d.ts";
|
||||
|
||||
export type ScopedClient = ReturnType<typeof createClient<paths>>;
|
||||
|
||||
/**
|
||||
* Create an openapi-fetch client bound to a specific instance. Use for views
|
||||
* that need to query non-active instances (e.g. side-by-side comparison).
|
||||
* For single-instance access, prefer `client.current` which tracks the active
|
||||
* instance via localStorage.
|
||||
* 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.
|
||||
*/
|
||||
export function createScopedClient(instance: Instance): ScopedClient {
|
||||
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
||||
if (instance.token) headers.Authorization = `Bearer ${instance.token}`;
|
||||
return createClient<paths>({ baseUrl: instance.baseUrl, headers, fetch: httpFetch });
|
||||
const { baseUrl, headers, fetch } = dispatchFor(instance);
|
||||
return createClient<paths>({ baseUrl, headers, fetch });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user