---
title: "Web tier ntawm Cloudflare Workers"
description: "Khiav Quire web tier uas muaj qee yam txo ntawm Cloudflare Workers."
image: "https://docs.quirelms.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.quirelms.com/hmn/llms.txt
> Use this file to discover all available pages before exploring further.

# Web tier ntawm Cloudflare Workers

<span id="the-web-tier-on-cloudflare-workers"></span>

Tus qauv nyob ntu 6 hauv `docs/architecture/23-ops.md`. Workers khiav web tier uas txo. Kom Workers muaj txhua yam sib npaug tsis nyob hauv txoj haujlwm (PRD ntu 12): yam uas target ua tsis tau yuav tsis txais thaum pib thiab qhia npe.

## Xwm txheej hauv release no <!--quire:status-in-this-release-->

Kev teeb tsa twb muaj (`apps/web/wrangler.jsonc`, Nitro preset `cloudflare-module`, Hyperdrive bridge thiab kev kuaj thaum pib). Worker xav tau storage phim S3 rau R2 (`QUIRE_STORAGE_DRIVER=s3`), realtime driver hla request (`QUIRE_REALTIME_DRIVER=durable_objects` lossis `centrifugo`), cache sib koom (`QUIRE_CACHE_DRIVER=postgres` lossis `valkey`) thiab HTTP email provider. Yog tsis muaj, Worker tsis kam pib thiab log qhia txhua setting. Durable Objects driver yog client txuas realtime Worker hauv `apps/realtime-worker` (ib Durable Object ib channel rau fan-out, presence thiab history; ib qho ib tus neeg rau disconnect); deploy nrog nws raws li hauv qab no lossis siv Centrifugo.

## Cov feem <!--quire:the-pieces-->

| Feem | Ntawm Cloudflare |
| --- | --- |
| `web` | Worker nrog `nodejs_compat` |
| Postgres | Sab nraud, hla Hyperdrive: `HYPERDRIVE` rau application role, `REPORT_HYPERDRIVE` rau report role hauv physical database tib yam. Thaum pib web tier luam txhua connection string rau `DATABASE_URL` thiab `QUIRE_REPORT_DATABASE_URL` |
| Ntaub ntawv | R2 ntawm S3 API (`S3_ENDPOINT=https://<account>.r2.cloudflarestorage.com`); `FILES` binding txuas bucket |
| Background jobs | pg-boss hla Hyperdrive thaum yuav tsum tso job ua ke nrog write. Yog companion worker muaj `QUIRE_QUEUE_DRIVER=cloudflare`, light jobs (notification tsis teem thiab webhook xa) mus Cloudflare Queues, ces tsis polling Postgres. Companion worker khiav ob hom |
| Realtime | Realtime Worker, `apps/realtime-worker`, nrog Durable Objects |
| `worker`, `scheduler`, `collab`, `content`, ClamAV, Gotenberg, ffmpeg | Companion container host. Worker khiav tsis tau lawv |
| Tracing | Workers observability, qhib hauv `wrangler.jsonc` |

`REPORT_HYPERDRIVE` muab report role rau physical database uas `HYPERDRIVE` taw rau. Target no tsis pab tenant uas pinned rau physical database ntxiv, raws li piav hauv qab.

## Yam uas target no ua tsis tau <!--quire:what-this-target-cannot-do-->

Thaum pib, tsis kam thiab teev txhua teeb meem ua ke:

- **Tsis muaj SMTP.** Siv HTTP provider hauv `QUIRE_EMAIL_PROVIDER_CONFIG`.
- **Tsis muaj local disk.** `QUIRE_STORAGE_DRIVER` yuav tsum yog object storage.
- **Tsis muaj realtime lossis cache hauv process.** Workers tsis sib koom memory hla request, yog li tsis txais `QUIRE_REALTIME_DRIVER=inprocess` thiab `QUIRE_CACHE_DRIVER=memory`.
- **Worker khiav tsis tau ClamAV, Gotenberg lossis ffmpeg.** Tsis txais `CLAMAV_URL`, `GOTENBERG_URL` thiab `FFMPEG_PATH` teeb rau Worker; muab rau companion worker.
- **Tsis muaj koom haum siv database tshwj xeeb.** Hyperdrive bindings ntawm Worker ruaj thaum deploy, yog li koom haum muaj database nyias pom nplooj “unavailable here”. Siv Compose lossis Vercel rau nws.

Thiab ib yam uas tsis raug tsis kam tiam sis yuav tsum paub: **prerender thiab incremental static regeneration tsis ua haujlwm ntawm Workers**, txawm framework docs hais li cas. Txhua route render raws request.

Ntawm target no cia transaction luv thiab tsis txhob tuav thaum hu network: Hyperdrive rov pib session state thaum connection rov pool, ces teem tenant context hauv txhua transaction.

## Deploy <!--quire:deploying-->

1. Tsim cov resource:
   ```sh
   bun run --bun wrangler hyperdrive create quire-app --connection-string="postgres://quire_app:...@db.example.com:5432/quire"
   bun run --bun wrangler hyperdrive create quire-report --connection-string="postgres://quire_report:...@db.example.com:5432/quire"
   bun run --bun wrangler r2 bucket create quire-files
   bun run --bun wrangler queues create quire-jobs
   ```
   Muab ob Hyperdrive ID tso hauv `apps/web/wrangler.jsonc`.
2. Siv `bun run --bun wrangler secret put <NAME>` ib zaug rau txhua secret ntawm `apps/web`: `QUIRE_SECRET_KEY`, `QUIRE_MASTER_KEY`, `QUIRE_EMAIL_PROVIDER_CONFIG`, `S3_ACCESS_KEY_ID`, `S3_SECRET_ACCESS_KEY`, `QUIRE_COLLAB_SIGNING_KEY`, `QUIRE_REALTIME_WORKER_SECRET`. Chaw teeb ib txwm (`QUIRE_APP_ORIGIN`, `QUIRE_CONTENT_ORIGIN`, `QUIRE_PLATFORM_DOMAINS`, `QUIRE_DATABASE_ID`, `S3_ENDPOINT`, `S3_BUCKET`, `QUIRE_COLLAB_URL`) muab hauv `vars`.
3. Tsim thiab deploy ntawm `apps/web`:
   ```sh
   NITRO_PRESET=cloudflare-module bun run build
   bun run --bun wrangler deploy
   ```
4. Deploy realtime Worker nrog `QUIRE_REALTIME_WORKER_SECRET` ntawm web tier thiab token secret ua `QUIRE_REALTIME_TOKEN_SECRET` (web tier kos realtime token siv nws tus `QUIRE_REALTIME_TOKEN_SECRET`, lossis `QUIRE_SECRET_KEY` yog thawj qhov tsis teeb; siv tus uas nws siv), thiab teeb `QUIRE_REALTIME_WORKER_URL` ntawm web tier taw rau nws qhov chaw nyob:
   ```sh
   cd apps/realtime-worker
   bun run --bun wrangler secret put QUIRE_REALTIME_WORKER_SECRET
   bun run --bun wrangler secret put QUIRE_REALTIME_TOKEN_SECRET
   bun run --bun wrangler deploy
   ```
5. Yuav siv Cloudflare Queues rau light jobs, tsim ib queue rau txhua light queue thiab teeb cov nqi hauv companion worker (API token yuav tsum nyeem thiab sau Queues tau):
   ```sh
   bun run --bun wrangler queues create quire-events-notifications
   bun run --bun wrangler queues create quire-events-notifications-dead
   bun run --bun wrangler queues create quire-events-webhooks
   bun run --bun wrangler queues create quire-events-webhooks-dead
   ```
   Teeb `QUIRE_QUEUE_DRIVER=cloudflare`, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_QUEUES_TOKEN`, thiab `QUIRE_QUEUE_PREFIX` yog tsis siv `quire-`.
6. Khiav companion host raws [phau Vercel](/hmn/ops/vercel/), kauj ruam 3. Migrations khiav nyob ntawd ua ntej deploy Worker txhua zaus.

Yog teeb tsa tsis raug, `bun run --bun wrangler tail` qhia “The web tier did not start on cloudflare”, ces teev setting twg yuav hloov.

Source: https://docs.quirelms.com/hmn/ops/cloudflare/index.mdx
