Back to Rivet

Chat Room

examples/chat-room-render/README.md

2.3.22.3 KB
Original Source

Note: This is the Render-optimized version of the chat-room example. It adds a production HTTP server, Vite build, and a render.yaml Blueprint for deploying to Render.

Chat Room

Example project demonstrating real-time messaging and actor state management.

Getting Started

sh
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/chat-room
npm install
npm run dev

Features

  • Real-time messaging: Broadcast messages to all connected clients instantly
  • Persistent chat history: Messages automatically saved in actor state across restarts
  • Multiple chat rooms: Each room is a separate actor instance with isolated state
  • Event-driven architecture: Use actor events to push updates to clients in real-time

Implementation

The chat room demonstrates core Rivet Actor patterns for real-time communication:

  • Actor Definition (src/actors.ts): chatRoom actor with persistent message history and newMessage broadcast events
  • Server Setup (src/server.ts): Hono app routing /api/rivet/* to the registry handler
  • React Frontend (frontend/app/App.tsx): useActor hook with real-time event subscriptions

Deploy on Render

  1. Set Root Directory to examples/chat-room-render if deploying from the monorepo.
  2. Add the following environment variables in your Render service:
VariableDescription
RIVET_ENDPOINTBackend endpoint URL from your Rivet Cloud project
RIVET_PUBLIC_ENDPOINTPublic endpoint URL from your Rivet Cloud project
  1. In the Rivet dashboard, point Connect your backend at your service's HTTPS URL.

RIVET_ENVOY_VERSION is automatically derived from Render's RENDER_GIT_COMMIT — no manual bump needed per deploy. Set it explicitly to override.

Resources

License

MIT