Is it possible to run websocket (trpc subscriptions) server in the same process as nextjs app?

Official TRPC example on using websockets with next (https://github.com/trpc/examples-next-prisma-websockets-starter) seem to run them separately, but it doesn't really look right to me, as i'm not ever planning to run my app on edge or serverless, and just want this stupid-simple monolith.
5 Replies
Leonidas
Leonidas2y ago
Absolutely But websockets require that the client always connects to the same server. Which makes a serverless deployment impossible You could use aws ecs / kubernetes with a sticky load balancer Or simply run one server if elastic scaling is not needed
dan
dan2y ago
That example does run one process. It uses NextJS custom server. src/server/prodServer.ts is what programmatically starts nextjs
GamerZero
GamerZero2y ago
So is it just using separate processes in dev? I'm currently trying to set it up in my existing app created with create-t3-app. It already uses some utility stuff like ramda in it's trpc routers, so i've got into problems with running tsx watch src/server/trpc/wssDevServer.ts which I saw in this templates package.json.
dan
dan2y ago
yes in dev is uses 2 processes, I would imagine you can do it on a single process but there is probably a reason why two separate ones have been used in dev. probably something todo with hmr if I had to guess.
GamerZero
GamerZero2y ago
Yeah problems with hmr is what I've just thought about. Would try to set up this tsx thing properly then, or replace it with something...
Want results from more Discord servers?
Add your server