38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { createTRPCProxyClient, httpLink } from '@trpc/client';
|
|
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
|
import type { TZippoRouter } from 'zippo-interface';
|
|
import { env } from '../env.server';
|
|
|
|
const makeClient = () =>
|
|
createTRPCProxyClient<TZippoRouter>({
|
|
links: [
|
|
httpLink({
|
|
url: env.ZIPPO_URL,
|
|
headers() {
|
|
return { apiKey: env.ZIPPO_API_KEY };
|
|
},
|
|
}),
|
|
],
|
|
});
|
|
|
|
let trpcClient: ReturnType<typeof makeClient> | undefined;
|
|
|
|
declare global {
|
|
var __trpc_client: ReturnType<typeof makeClient> | undefined;
|
|
}
|
|
|
|
if (env.NODE_ENV === 'development') {
|
|
if (!global.__trpc_client) {
|
|
global.__trpc_client = makeClient();
|
|
}
|
|
trpcClient = global.__trpc_client;
|
|
} else {
|
|
trpcClient = makeClient();
|
|
}
|
|
|
|
export const client = trpcClient as ReturnType<typeof makeClient>;
|
|
|
|
export type RouterInputs = inferRouterInputs<TZippoRouter>;
|
|
|
|
export type RouterOutputs = inferRouterOutputs<TZippoRouter>;
|