39 lines
827 B
TypeScript
39 lines
827 B
TypeScript
import type { AppRouter } from './routers';
|
|
import getUrls from '@/config/urls';
|
|
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
|
import { createTRPCNext } from '@trpc/next';
|
|
import SuperJSON from 'superjson';
|
|
import { isServer } from 'tools/common';
|
|
|
|
const { BASE_PATH, PORT } = getUrls();
|
|
|
|
function getBaseUrl() {
|
|
if (!isServer()) return BASE_PATH;
|
|
|
|
return `http://localhost:${PORT ?? 3000}${BASE_PATH}`;
|
|
}
|
|
|
|
const url = `${getBaseUrl()}/api/trpc`;
|
|
|
|
export const trpcClient = createTRPCNext<AppRouter>({
|
|
config() {
|
|
return {
|
|
links: [
|
|
httpBatchLink({
|
|
url,
|
|
}),
|
|
],
|
|
transformer: SuperJSON,
|
|
};
|
|
},
|
|
});
|
|
|
|
export const trpcPureClient = createTRPCProxyClient<AppRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url,
|
|
}),
|
|
],
|
|
transformer: SuperJSON,
|
|
});
|