mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add svelte
This commit is contained in:
31
apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs
Normal file
31
apps/cli/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs
Normal file
@@ -0,0 +1,31 @@
|
||||
import { PUBLIC_SERVER_URL } from "$env/static/public";
|
||||
import { createORPCClient } from "@orpc/client";
|
||||
import { RPCLink } from "@orpc/client/fetch";
|
||||
import type { RouterClient } from "@orpc/server";
|
||||
import { createORPCSvelteQueryUtils } from "@orpc/svelte-query";
|
||||
import { QueryCache, QueryClient } from "@tanstack/svelte-query";
|
||||
import type { appRouter } from "../../../server/src/routers/index";
|
||||
|
||||
export const queryClient = new QueryClient({
|
||||
queryCache: new QueryCache({
|
||||
onError: (error) => {
|
||||
console.error(`Error: ${error.message}`);
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export const link = new RPCLink({
|
||||
url: `${PUBLIC_SERVER_URL}/rpc`,
|
||||
{{#if auth}}
|
||||
fetch(url, options) {
|
||||
return fetch(url, {
|
||||
...options,
|
||||
credentials: "include",
|
||||
});
|
||||
},
|
||||
{{/if}}
|
||||
});
|
||||
|
||||
export const client: RouterClient<typeof appRouter> = createORPCClient(link);
|
||||
|
||||
export const orpc = createORPCSvelteQueryUtils(client);
|
||||
Reference in New Issue
Block a user