Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

createClientRpc.ts

20 lines646 Bytes

1import { TSS_SERVER_FUNCTION } from '../constants'
2import { getStartOptions } from '../getStartOptions'
3import { serverFnFetcher } from './serverFnFetcher'
4import type { ClientFnMeta } from '../constants'
5​
6export function createClientRpc(functionId: string) {
7 const url = process.env.TSS_SERVER_FN_BASE + functionId
8 const serverFnMeta: ClientFnMeta = { id: functionId }
9​
10 const clientFn = (...args: Array<any>) => {
11 const startFetch = getStartOptions()?.serverFns?.fetch
12 return serverFnFetcher(url, args, startFetch ?? fetch)
13 }
14​
15 return Object.assign(clientFn, {
16 url,
17 serverFnMeta,
18 [TSS_SERVER_FUNCTION]: true,
19 })