Here's how to setup trpc in a +server.ts endpoint instead of hooks.server.ts #87
multiplehats
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Long story short, I'm using Prisma in my trpc routes, but I'm also using a few one off edge routes on Vercel that have nothing to do with my trpc routes.
However, if you use
createTRPCHandle
inhooks.server.ts
, it will load all your routes and thus Prisma, which is not compatible on the edge.After tweeting about this, @paoloricciuti made the suggestion to set it up on a single endpoint (similar to Next.js).
So I figured, I'll make a quick post to help others out.
Create a
+server.ts
routeRoute should look like this:
routes/api/trpc/[trpc]
where the path can be anything.Due the way the
createTRPCHandle
in this package is created, we can't directly use it and have to re-use some of the logic. Ideally this logic can be a separated exported function in this package that makes this easier in the future.Then in your helper (see the docs)
Beta Was this translation helpful? Give feedback.
All reactions