ItsWendell
ItsWendellโ€ข2y ago

Proxy TRPC server to another client

I've two TRPC servers, one essentially acts like a proxy, it validates auth and based on a specific property it forwards you to the destined server (with that one property removed). Now I have to write all those queries and mutation twice, is there a simpeler way to do this? Is there any way to bind a specific TRPC client to a server?
5 Replies
ItsWendell
ItsWendellโ€ข2y ago
A little bit more context, the other server is a Cloudflare Workers Durable Object, which I managed to get to work with TRPC. I can essentially do: const trpc = MyDurableObject.getClient(id) which will return a TRPC client instance.
Alex / KATT ๐Ÿฑ
Unsure if it helps but here is an example how you can glue services in the client https://github.com/trpc/trpc/tree/main/examples/soa
GitHub
trpc/examples/soa at main ยท trpc/trpc
๐Ÿง™โ€โ™€๏ธ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - trpc/examples/soa at main ยท trpc/trpc
ItsWendell
ItsWendellโ€ข2y ago
Hmh no I want to glue a specific client to a server, not a client to two servers or two routers into 1 server, I want a trpc router to act like a proxy. Since Durable Objects are not accessable outside of Workers, both of which can be viewed as servers. E.g. server A can only access server B, but I want the client to be able to access server B through server A.
Alex / KATT ๐Ÿฑ
We don't have anything automatic for that but wouldn't be impossible to build Sounds like graphql federation but for trpc haha
ItsWendell
ItsWendellโ€ข2y ago
Yeah that would be awesome to have, especially in the serverless context