28 lines
853 B
TypeScript
28 lines
853 B
TypeScript
import { createORPCClient } from '@orpc/client'
|
|
import { RPCLink } from '@orpc/client/fetch'
|
|
import { createRouterClient, type RouterClient } from '@orpc/server'
|
|
import { createTanstackQueryUtils } from '@orpc/tanstack-query'
|
|
import { createIsomorphicFn } from '@tanstack/react-start'
|
|
import { getRequestHeaders } from '@tanstack/react-start/server'
|
|
import { router } from './router'
|
|
import type { APIClient } from './types'
|
|
|
|
const getORPCClient = createIsomorphicFn()
|
|
.server(() =>
|
|
createRouterClient(router, {
|
|
context: () => ({
|
|
headers: getRequestHeaders(),
|
|
}),
|
|
}),
|
|
)
|
|
.client(() => {
|
|
const link = new RPCLink({
|
|
url: `${window.location.origin}/api/rpc`,
|
|
})
|
|
return createORPCClient<APIClient>(link)
|
|
})
|
|
|
|
const client: APIClient = getORPCClient()
|
|
|
|
export const orpc = createTanstackQueryUtils(client)
|