How do tRPC WebSockets work with NextJS
Hey!
I've recently stumbled upon this repo: https://github.com/trpc/examples-next-prisma-websockets-starter.
I'm a little confused on how it would be able to hold a connection with a serverless environment.
Solution:Jump to solution
it looks like they setup a websocket server there, and host they on "render"
12 Replies
Solution
it looks like they setup a websocket server there, and host they on "render"
So the site and websocket server are hosted differently? Or everything is hosten on render?
pretty sure everything is hosted on render
try to deploy that exmaple app yourself on render to see how it works ig
on the example there are 2 servers running on the same machine
GitHub
examples-next-prisma-websockets-starter/package.json at main · trpc...
🏓 tRPC Next.js WebSocket Starter. Contribute to trpc/examples-next-prisma-websockets-starter development by creating an account on GitHub.
in the real world, you are going to use something like pusher, socketi or whatever
why is it preferable? trpc subscriptions are not production ready or?
trpc is fine
the ws side is the faulty one
vercel does not host any ws service
vercel run on lambdas, so you wont host there as well
in the example is fine to host both of them, but in the real world you wont gonna use the same
its not possible to host the ws server on render or something and the lambdas / app itself on vercel?
yep, its a alternative
Question from a beginner, if we are running a linux bare metal server that we have configured to be able to run next.js apps, then it should be fine to use ws, right? The reason not to use ws is not that the ws package is inherently limited, but that some hosting platforms to not allow it. Correct?
Yes i think you're totally fine running something like this on your own linux server