mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-05 19:49:57 +09:00
Remix Vite no longer polyfills streams and fetch. Should be safe to drop them. Stream polyfills broke ai, fetch broke trpc.
45 lines
1.0 KiB
TypeScript
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;
|
|
};
|