Integrating hono.js with tRPC in Next.js: Routing and Context Considerations
I want to combine Hono.js with tRPC. I followed the guide on the 3rd party middleware made by hono for a tRPC server, and now I have set up the hono tRPC server 3rd party middleware similar to the code below:
Now, where should I place this code in Next.js? Should it go in
Also, what is the best approach regarding context—should I use the tRPC context or the Hono.js context?
Now, where should I place this code in Next.js? Should it go in
app/api/[[...route]]/route.ts or in app/api/trpc/[trpc]/route.ts?Also, what is the best approach regarding context—should I use the tRPC context or the Hono.js context?
Solution
Option 1. N -> H -> T (this is to use
Option 2. N -> T - You use the tprc adapter for nextjs directly and
I think you might missunderstanding what's the purpose goal of HonoJS, vs nextjs api/server and how they interact with TRPC
src/app/api/[[...route]) as the example belowOption 2. N -> T - You use the tprc adapter for nextjs directly and
src/app/api/trpc/[trpc]/routeI think you might missunderstanding what's the purpose goal of HonoJS, vs nextjs api/server and how they interact with TRPC