Hono tRPC Server body issue
I have been trying to get Cloudflare Workers, Hono and tRPC working for tens of hours now.
I am using the
@hono/trpc-server package which gives me middleware for trpc to run with hono. They even have an example with cloudflare workers and a d1 database, so I know it is possible to do what I am trying to do.
The problem I am having is that tRPC is not reading the body properly, or at all. Take this function as an example:
It never even gets to the mutation part at all because validation fails. Using errorFormatting with tRPC shows me that input is undefined when getting passed by postman, which is weird because I am definitely sending a title. It all worked before when I hadn't moved to Cloudflare Workers and before I was using the hono trpc-server package.
This is how I serve the app:
Here is some more context so you can understand my code a little better.
context.ts
How can I get tRPC to start recognizing the input? The context and database queries work as intended, it's just the input that is not working.4 Replies
It looks reasonable, I would put some console logs around to confirm if hono is even receiving the body and such
I’ve seen hono and tRPC integrated in the wild for CF so it definitely can work
I tried making this little debugger to see what was getting through
It returned:
The body is there, but the tRPC procedure does not pick it up? I'm not sure
The complicated setup is making me question my stack but I don't know what would have even been simpler
Maybe have a look here
https://github.com/iterate/iterate/blob/main/apps/os/backend/worker.ts
GitHub
iterate/apps/os/backend/worker.ts at main · iterate/iterate
The most hackable AI agent. Contribute to iterate/iterate development by creating an account on GitHub.
Looks like they just use our fetch adapter instead of the hono package which won’t have any real downsides I believe, possibly there’s an issue or version mismatch with that package you’re using