Files
webstudio/packages/trpc-interface/src/shared/client.ts
Bogdan Chadkin 6f3ac9d20a refactor: drop fetch polyfills (#3125)
Remix Vite no longer polyfills streams and fetch.
Should be safe to drop them.

Stream polyfills broke ai, fetch broke trpc.
2024-04-10 10:56:56 +07:00

45 lines
1.0 KiB
TypeScript

import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
import {
sharedRouter,
type TrpcInterfaceClient,
type SharedRouter,
} from "./shared-router";
import { callerLink } from "../trpc-caller-link";
type SharedClientOptions = {
url: string;
token: string;
branchName: string | undefined;
};
export const createTrpcProxyServiceClient = (
options?: SharedClientOptions | undefined
): TrpcInterfaceClient => {
if (options !== undefined) {
const remoteClient = createTRPCProxyClient<SharedRouter>({
links: [
httpBatchLink({
url: options.url,
headers: () => ({
Authorization: options.token,
// We use this header for SaaS preview service discovery proxy
"x-branch-name": options.branchName,
}),
}),
],
});
return remoteClient;
}
const client = createTRPCProxyClient<SharedRouter>({
links: [
callerLink({
appRouter: sharedRouter,
}),
],
});
return client;
};