Session Relay

Deploy to Cloudflare

Run Session Relay on Cloudflare Workers, with no server to maintain. It's the same app as the Docker version, with the same features, CLI and web app. Pick whichever suits you:

Docker (self-hosting.md) Cloudflare (this guide)
You run A Linux server with Docker Nothing. Cloudflare runs the Worker
Database Postgres in Docker Any Postgres (Neon, Supabase, RDS…) through Hyperdrive
Full transcripts Docker volume R2 bucket
Web app Served by the server Workers Static Assets
Expiry cleanup Hourly timer Cron Trigger
First-run setup code Printed in the server logs A secret you set (SETUP_CODE)
Migrations Run on startup You run them before each deploy (one command)

What you need

1. Get the code and build

git clone https://github.com/Ryrahul/session-relay.git
cd session-relay
npm ci && npm run build
npx wrangler login                    # opens the browser

2. Create the database tables

DATABASE_URL="postgres://user:password@host/db?sslmode=require" \
  node packages/server/dist/db/migrate-cli.js

3. Create Hyperdrive and R2

cd packages/server
npx wrangler hyperdrive create session-relay --caching-disabled \
  --connection-string="postgres://user:password@host/db?sslmode=require"
npx wrangler r2 bucket create session-relay-transcripts

--caching-disabled matters: Hyperdrive caches query results for 60 seconds by default, so an edit, a new comment or a settings change could look like it didn't save. Session Relay needs every read to be current. Already created one with caching? npx wrangler hyperdrive update <id> --caching-disabled.

4. Configure

Edit packages/server/wrangler.jsonc:

Then choose a first-run setup code and store it as a secret:

npx wrangler secret put SETUP_CODE          # e.g. type: KDQX-7MRA-4ZTP

5. Deploy

npx wrangler deploy

Open your URL. It shows Set up Session Relay. Enter the setup code, your organization's name, and your name and email. You become the owner; your token is shown once.

Setup closes for good once an organization exists, but remove the secret anyway:

npx wrangler secret delete SETUP_CODE

Then invite your team from Members → Invite with a link, and everyone follows Getting started.

Updating

git pull && npm ci && npm run build
DATABASE_URL="…" node packages/server/dist/db/migrate-cli.js     # migrations first
cd packages/server && npx wrangler deploy

Migrations are additive, so the running version keeps working while they apply. To undo a bad deploy: npx wrangler rollback.

Backups

Moving from Docker to Cloudflare

  1. On the Docker server, take a database backup:
    docker compose -f deploy/docker-compose.yml --env-file deploy/.env exec -T postgres pg_dump -U relay -d relay | gzip > relay.sql.gz
    
  2. Restore it into the new Postgres. Skip step 2 of this guide; the dump already has the tables.
    gunzip -c relay.sql.gz | psql "$DATABASE_URL"
    
  3. Copy full transcripts from the transcripts volume into R2:
    scripts/copy-transcripts-to-r2.sh /var/lib/docker/volumes/<project>_transcripts/_data session-relay-transcripts
    
  4. Deploy (steps 3–5, without SETUP_CODE: your organization already exists).
  5. Point your domain at the Worker. Everyone keeps their tokens. If the address changes, they run relay login --server <new url> once.

Troubleshooting

Symptom Fix
500 on every API call npx wrangler tail shows the error. Most often the Hyperdrive id is wrong or the database is unreachable
The setup page doesn't appear on a new install SETUP_CODE isn't set; run npx wrangler secret put SETUP_CODE and reload
relation "…" does not exist Migrations didn't run against this database (step 2)
Custom domain doesn't work The domain's DNS has to be on Cloudflare; until then use the workers.dev address
Changes take up to a minute to show (edits, comments, settings) Hyperdrive query caching is on: npx wrangler hyperdrive update <id> --caching-disabled
429 Too many requests Public endpoints (invites, browser login, setup) are rate-limited per IP; wait a minute

Edit this page on GitHub