27 lines
744 B
TypeScript
27 lines
744 B
TypeScript
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client'
|
|
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
|
|
import { trpcRouter, type TrpcRouter } from '~/server/routers/_app'
|
|
|
|
// This simulates the server without HTTP
|
|
function serverHandler(path: string, req: Request) {
|
|
return fetchRequestHandler({
|
|
endpoint: '/api/trpc',
|
|
router: trpcRouter,
|
|
req,
|
|
createContext: () => ({}),
|
|
})
|
|
}
|
|
|
|
export function createTestTrpcClient() {
|
|
return createTRPCProxyClient<TrpcRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url: 'http://localhost/api/trpc',
|
|
fetch: (input, init) => {
|
|
return serverHandler(input as string, new Request(input as string, init))
|
|
},
|
|
}),
|
|
],
|
|
})
|
|
}
|