@@ -3,15 +3,16 @@ import { RPCLink } from "@orpc/client/fetch";
33import { createTanstackQueryUtils } from "@orpc/tanstack-query";
44import { QueryCache, QueryClient } from "@tanstack/react-query";
55import { toast } from "sonner";
6- {{ #if (includes frontend " tanstack-start" )}}
6+ {{ #if (and ( includes frontend " tanstack-start" ) ( eq backend " self " ) )}}
77import { createRouterClient } from "@orpc/server";
88import type { RouterClient } from "@orpc/server";
99import { createIsomorphicFn } from "@tanstack/react-start";
1010import { appRouter } from "@{{ projectName }} /api/routers/index";
1111import { createContext } from "@{{ projectName }} /api/context";
12- {{ #unless (eq backend " self" )}}
12+ {{ else if (includes frontend "tanstack-start")}}
13+ import type { RouterClient } from "@orpc/server";
14+ import { appRouter } from "@{{ projectName }} /api/routers/index";
1315import { env } from "@{{ projectName }} /env/web";
14- {{ /unless }}
1516{{ else }}
1617import type { AppRouterClient } from "@{{ projectName }} /api/routers/index";
1718{{ #unless (eq backend " self" )}}
@@ -32,30 +33,18 @@ export const queryClient = new QueryClient({
3233 }),
3334});
3435
35- {{ #if (includes frontend " tanstack-start" )}}
36+ {{ #if (and ( includes frontend " tanstack-start" ) ( eq backend " self " ) )}}
3637const getORPCClient = createIsomorphicFn()
3738 .server(() =>
3839 createRouterClient(appRouter, {
3940 context: async ({ req }) => {
40- {{ #if (eq backend " self" )}}
41- return createContext({ req });
42- {{ else if (eq backend "hono")}}
43- return createContext({ context: req });
44- {{ else if (eq backend "elysia")}}
45- return createContext({ context: req });
46- {{ else if (eq backend "express")}}
4741 return createContext({ req });
48- {{ else if (eq backend "fastify")}}
49- return createContext(req.headers);
50- {{ else }}
51- return createContext();
52- {{ /if }}
5342 },
5443 }),
5544 )
5645 .client((): RouterClient<typeof appRouter> => {
5746 const link = new RPCLink({
58- url: {{ #if ( eq backend " self " ) }} `${window.location.origin}/api/rpc`{{ else }} `${env.VITE_SERVER_URL}/rpc` {{ /if }} ,
47+ url: `${window.location.origin}/api/rpc`,
5948{{ #if (eq auth " better-auth" )}}
6049 fetch(url, options) {
6150 return fetch(url, {
@@ -69,6 +58,24 @@ const getORPCClient = createIsomorphicFn()
6958 return createORPCClient(link);
7059 });
7160
61+ export const client: RouterClient<typeof appRouter> = getORPCClient();
62+ {{ else if (includes frontend "tanstack-start")}}
63+ const link = new RPCLink({
64+ url: `${env.VITE_SERVER_URL}/rpc`,
65+ {{ #if (eq auth " better-auth" )}}
66+ fetch(url, options) {
67+ return fetch(url, {
68+ ...options,
69+ credentials: "include",
70+ });
71+ },
72+ {{ /if }}
73+ });
74+
75+ const getORPCClient = () => {
76+ return createORPCClient(link) as RouterClient<typeof appRouter>;
77+ };
78+
7279export const client: RouterClient<typeof appRouter> = getORPCClient();
7380{{ else }}
7481export const link = new RPCLink({
@@ -103,3 +110,4 @@ export const client: AppRouterClient = createORPCClient(link)
103110{{ /if }}
104111
105112export const orpc = createTanstackQueryUtils(client)
113+
0 commit comments