tRPCttRPC
Powered by
FinnF
tRPC•3y ago•
5 replies
Finn

How do I setup subscriptions with websockets in Next.js 14 app router?

All I've found were some older examples for the pages router which for me were not very understandable or I'm just stupid. For the most part I'm having trouble understanding how exactly the websocket server is started. Does it start with Next.js or is it something that you have to seperatly?

Would be glad if someone can give me some insight.
Solution
btw i did it: You can check out the project. it uses app directory. I am using t3 stack here https://github.com/Roopaish/evento
main files to look at are: tsconfig.server.json, src/server/ws-dev-server.ts (need to update prod one, will do later), trpc/react.tsx, src/server/routers/post.ts, app/(all)/post/page.tsx

And also don't export thing from wss-dev-server.ts. Cause if you use those exports, next js server will try to use that port to create new WebSocketServer.
Jump to solution
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Next 14 app router
Fitim BytyqiFFitim Bytyqi / ❓-help
2y ago
Next.js App router
BrianBBrian / ❓-help
8mo ago
WebSocket Subscriptions in Next.js 14 Using `fetchRequestHandler` and `createTRPCReact`
Hemant RajputHHemant Rajput / ❓-help
2y ago
Questions around trpc with next.js app router
HobbsHHobbs / ❓-help
2y ago