aboutsummaryrefslogtreecommitdiffstats
path: root/apps/cli/src/lib/trpc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/cli/src/lib/trpc.ts')
-rw-r--r--apps/cli/src/lib/trpc.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/apps/cli/src/lib/trpc.ts b/apps/cli/src/lib/trpc.ts
new file mode 100644
index 00000000..aa7aec21
--- /dev/null
+++ b/apps/cli/src/lib/trpc.ts
@@ -0,0 +1,22 @@
+import { getGlobalOptions } from "@/lib/globals";
+import { createTRPCClient, httpBatchLink } from "@trpc/client";
+import superjson from "superjson";
+
+import type { AppRouter } from "@hoarder/trpc/routers/_app";
+
+export function getAPIClient() {
+ const globals = getGlobalOptions();
+ return createTRPCClient<AppRouter>({
+ links: [
+ httpBatchLink({
+ url: `${globals.serverAddr}/api/trpc`,
+ transformer: superjson,
+ headers() {
+ return {
+ authorization: `Bearer ${globals.apiKey}`,
+ };
+ },
+ }),
+ ],
+ });
+}