From 2c2d05fd0a2c3c26d765f8a6beb88d907a097c1d Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sun, 11 Feb 2024 14:54:52 +0000
Subject: refactor: Migrating to trpc instead of next's route handers

---
 packages/web/lib/trpc.tsx | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 packages/web/lib/trpc.tsx

(limited to 'packages/web/lib/trpc.tsx')

diff --git a/packages/web/lib/trpc.tsx b/packages/web/lib/trpc.tsx
new file mode 100644
index 00000000..540c6ab5
--- /dev/null
+++ b/packages/web/lib/trpc.tsx
@@ -0,0 +1,20 @@
+"use client";
+import { httpBatchLink } from "@trpc/client";
+import type { AppRouter } from "@/server/api/routers/_app";
+
+import { loggerLink } from "@trpc/client";
+import { createTRPCClient } from "@trpc/client";
+
+export const api = createTRPCClient<AppRouter>({
+  links: [
+    loggerLink({
+      enabled: (op) =>
+        process.env.NODE_ENV === "development" ||
+        (op.direction === "down" && op.result instanceof Error),
+    }),
+    httpBatchLink({
+      // TODO: Change this to be a full URL exposed as a client side setting
+      url: `/api/trpc`,
+    }),
+  ],
+});
-- 
cgit v1.3-1-g0d28

