zobacz/Docs/Self-hosting

Self-hosting

The same build that cf deploy ships to Cloudflare runs in Docker on any server, including a platform that gives each customer their own Worker.

One app, two places to run it

A zobacz app is a Cloudflare Worker, and it runs off Cloudflare unchanged. mitarbeiter (the arbeit CLI, in packages/mitarbeiter) boots the cf build output on workerd through Miniflare, one Docker container per app, with Caddy in front for HTTPS. The app keeps its cloudflare.config.ts; the bindings it declares are wired to self-hosted backends.

The app code is identical in both places. Per-deployment settings (origins, hostnames, secrets) come from the environment, set by the stack manifest.

Start a stack

A stack is a mitarbeiter.config.ts listing the apps, their hostnames and their secrets. arbeit up builds each app, generates docker-compose and a Caddyfile from the manifest, and starts everything. Local hostnames (*.localhost, .test, .local) get mkcert certificates; run mkcert -install once so browsers trust them.

terminal
cd packages/mitarbeiter && npm install && npm run build && npm linkcd my-stackarbeit up            # build, generate compose + Caddyfile, docker compose up -darbeit ps            # health of every servicearbeit logs dash -f  # follow one app

The stack manifest

Each app names its folder and the host it answers on. env sets text vars at run time (they override the values baked by cf build); secrets names the keys that come from the gitignored config/.env. sharedD1 keeps the app's databases in one shared server. edge moves Caddy off ports 80 and 443 when the host already uses them.

mitarbeiter.config.ts
export default {  name: 'shop',  edge: { http: 8080, https: 8443 },  apps: [    { name: 'auth', dir: 'apps/auth', site: 'auth.shop.localhost', sharedD1: true },    {      name: 'dash',      dir: 'apps/dash',      site: 'dash.shop.localhost',      env: { SIGN_IN_URL: 'https://shop.localhost:8443/login' },      secrets: ['SESSION_SECRET'],    },  ],};

Workers for Platforms, self-hosted

A platform that gives every customer their own Worker (a store per merchant) needs more than one app per container. Add a dispatch block and mark the platform app with dispatch: true. mitarbeiter then runs one more service with two jobs.

The control plane answers the Cloudflare API calls the platform already makes to create, route and remove tenants: D1 databases (with time travel), KV namespaces, dispatch-namespace and account scripts with their assets, Workers Custom Domains, custom hostnames and routes. Same paths, same responses, so the platform only changes CF_API_BASE. It also holds every tenant database and KV namespace, and stores secret bindings encrypted.

The store pool runs each uploaded script as its own worker with the bindings its upload declared. A dispatcher in front routes each hostname to its tenant through the platform's hostname registry, the same KV contract the Cloudflare dispatcher reads, and serves the platform's DISPATCHER.get().

mitarbeiter.config.ts
dispatch: {  controlToken: '${MITARBEITER_CONTROL_TOKEN}',   // the platform's CF_PROVISION_TOKEN  dispatchToken: '${MITARBEITER_DISPATCH_TOKEN}',  registryKv: '<the platform registry binding id>',  namespace: 'stores',  storeDomain: 'stores.shop.localhost',            // tenants at <name>.stores.shop.localhost  smtpUrl: '${MITARBEITER_SMTP_URL}',             // send_email goes out over SMTP},apps: [  { name: 'platform', dir: 'apps/platform', site: 'platform.shop.localhost', sharedD1: true, dispatch: true },],

Adding a tenant leaves the others running

Tenants are spread over several workerd instances (MITARBEITER_POOL_SHARDS, default 8) by a hash of the script name. The dispatcher runs in its own instance, and its configuration lists no tenants, so it keeps running through uploads. When a tenant is added or upgraded, its shard reloads for about a second. Reads to that shard are retried through the reload; a write in that second gets a 503 with Retry-After. Tenants in other shards keep serving.

Certificates

Every app host gets its certificate from Caddy. Tenant hosts on a local store domain share one wildcard certificate. On a public domain, Caddy issues certificates on demand, for tenant subdomains and for customers' own domains alike, and asks the control plane first: a certificate is only issued for a hostname the platform has attached.

Operating it

Everything durable lives in Docker volumes: each app's state, the shared databases and the control plane's data. Back the volumes up. A tenant database can be bookmarked and restored through the same time travel calls the platform uses on Cloudflare.

The control plane can be published on the host's loopback (publishControl) for operators: its /d1 and /kv endpoints run queries and edit keys with the control token. Bind it to loopback or a private network: it holds every tenant's data.

terminal
curl -s -H "authorization: Bearer $MITARBEITER_CONTROL_TOKEN" \  -X POST http://127.0.0.1:18790/d1/q \  -d '{"db":"mvps-platform-db","sql":"SELECT count(*) AS n FROM stores","mode":"first"}'

What runs off Cloudflare

FeatureSelf-hostedHow
Workers, assets, cron, nodejs_compatSupportedworkerd through Miniflare
Durable Objects (SQLite)Supportedper container, on its volume
D1Supportedper container, or shared (sharedD1)
KV, R2Supportedper container; KV shared with tenants under dispatch
QueuesSupportedproducer and consumer in the same app
Service bindings between appsSupportedHTTP on the stack network
Dispatch namespaces (Workers for Platforms)Supportedthe dispatch service
send_emailSupportedSMTP relay (dispatch.smtpUrl)
Custom domains and certificatesSupportedCaddy, on-demand for tenants
Several servers, failoverNot availableone box per stack today
Workers AINot availableleft unbound; gate it behind a flag
Browser RenderingNot availableleft unbound
Cloudflare AccessNot availableput sign-in or a VPN in front
Workflows, ContainersWith a fallbackunbound; the app needs an inline fallback or a sidecar