Skip to content
Prova
Esc
↑↓navigate↵open⌘Jpreview
On this page

Self-hosting

Run the cloud workspace service on your own infrastructure. It is the same Next.js app as the hosted service.

On the Enterprise plan, run apps/cloud, the Next.js app behind the hosted service, dashboard, CLI API and published studios.

Configure

Variable Required What it is
BETTER_AUTH_SECRET Yes Long random string that signs sessions.
BETTER_AUTH_URL Yes The service address, such as https://studio.example.com; used in dashboard links.
DATABASE_URL No Postgres. Without it, embedded PGlite in apps/cloud/.data/, for trials.
STRIPE_SECRET_KEY No Turns billing on.
STRIPE_WEBHOOK_SECRET No Verifies Stripe webhooks.
STRIPE_TEAM_PRICE_ID No Per-unit monthly price for one editor.
TRUSTED_ORIGINS No In production, other addresses people sign in from, comma-separated, such as https://www.studio.example.com. BETTER_AUTH_URL is always trusted, and in development any origin is.
STUDIO_LIVE_URL No Where browsers and studios reach the live server, such as wss://live.example.com/live, when it runs apart from the website. Unset, it is the website’s own /live.
STUDIO_LIVE_SECRET No Signs live tokens when the live server runs apart; set the same value on both. Unset, BETTER_AUTH_SECRET signs them.
STUDIO_PREVIEW_URL No Turns on cloud previews: where they live, with {workspace} in the host, such as https://{workspace}.preview.studio.example.com. Needs Docker.
STUDIO_PREVIEW_RUNNER No separate when previews run in their own process (bun run --cwd apps/cloud start:preview), as in deploy/.

Without Stripe, billing is off and every workspace has Team features. With it, point a webhook at /api/billing/webhook for checkout.session.completed and customer.subscription.created, .updated and .deleted. Migrations in drizzle/ run on the first request.

Run

The service is one Node process: Next.js for pages and the API, and the live server for live files on the same port, at /live (WebSockets).

bun install
bun run build --filter=cloud
bun run --cwd apps/cloud start   # or `bun run --cwd apps/cloud dev` on http://localhost:3011

Behind a proxy or load balancer, allow WebSocket upgrades on /live. Run one instance, or pin each workspace’s connections to one instance: live documents are held in memory between saves.

Hosts without WebSockets

Serverless hosts such as Vercel run Next.js but not the live server. Run the live server on its own, anywhere Node runs, against the same Postgres:

DATABASE_URL=postgres://… STUDIO_LIVE_SECRET=… PORT=3012 bun run --cwd apps/cloud start:live

Then set STUDIO_LIVE_URL=wss://<that host>/live and the same STUDIO_LIVE_SECRET on the website. PGlite cannot be shared between two processes, so this needs DATABASE_URL. The live server needs no Stripe key: it reads each workspace’s plan when someone joins, and the website’s live tokens say whether billing is on, so that on a lapsed plan everyone follows the files without changing them.

Docker

docker build -f apps/cloud/Dockerfile -t dex .
docker run -p 3000:3000 \
  -e DATABASE_URL=postgres://… -e BETTER_AUTH_SECRET=… \
  -e BETTER_AUTH_URL=https://studio.example.com dex

Pass variables with -e or your secrets manager. With PGlite, mount /repo/apps/cloud/.data; beyond a trial, use Postgres.

deploy/ in the repository runs everything on one VM with Docker Compose: the website and live server, cloud previews with a locked-down sandbox per workspace (gVisor when installed), Postgres, and Caddy for HTTPS, including certificates for each workspace’s preview host. Follow deploy/README.md.

Point studios at it

npx dex cloud login --token <token> --url https://studio.example.com
npx dex cloud link --workspace design --url https://studio.example.com

studio.cloud.json saves the address for teammates.

Was this page helpful?