Delivery
Websites read published content from routes the CMS serves on your Worker. They need no account and no token: only published documents and files under public/ are served.
How content gets there
Section titled “How content gets there”When a document is published, TapeDB hands the change to the CMS after the commit, inside the workspace’s Durable Object. The CMS writes the published document to the CONTENT R2 bucket; on unpublish or delete it removes it. Changes are applied in order and ordered by rev, so a repeated delivery never replaces a newer revision with an older one. A change that fails to apply is retried until it succeeds, and later changes wait for it.
There is no endpoint that accepts changes. Nothing outside your Worker can write to the delivery path.
Under tapedb dev a publish reaches the delivery routes in about a second; on a deployed Worker, in two to three seconds.
Routes
Section titled “Routes”| Route | Serves |
|---|---|
GET /content/:workspace/:type/:id |
a published document |
GET /content/:workspace/:type?slug=:slug |
a published document, by slug |
GET /content/:workspace/:type |
published documents of a type, a page at a time |
GET /img/:workspace/:path |
an image under public/, resized and cropped around its focal point |
A document comes back as JSON: its fields, id, rev, publishedAt, createdAt and updatedAt. A strong reference appears as <field>Id, a weak one as <field>Ref. Anything not published, or not existing, is 404 { "error": "not_found" }.
{ "id": "0d3c…", "rev": 3, "publishedAt": 1795867200000, "title": "Hello again, World", "slug": "hello-world", "cover": { "path": "public/media/harbour-at-dusk.png", "alt": "The harbour at dusk", "x": 0.72, "y": 0.4 }, "body": { "type": "doc", "content": [ … ] }, "authorId": "8f1a…", "createdAt": 1795860000000, "updatedAt": 1795867200000}GET /content/:workspace/:type answers { items, total, cursor }:
| Parameter | |
|---|---|
limit |
1 to 100, default 20 |
cursor |
the cursor of the previous page; null on the last page |
order |
publishedAt (default, newest first as -publishedAt) or a boolean, select, date, number, slug or reference field; a leading - for descending |
where.<field>=<value> |
equality on the same kinds of field, e.g. where.section=News&where.featured=true |
Ordering or filtering on any other kind of field is 400 with bad_order or bad_where.
References
Section titled “References”?expand=author,related on any of the routes replaces those reference fields with the documents they point at, if published, under the field’s own name (author, related). An unpublished or missing target expands to null. Naming a field that is not a reference is 400 bad_expand.
Images
Section titled “Images”/img/:workspace/:path takes:
| Parameter | |
|---|---|
w, h |
width and height in pixels; with both, the image is cropped to fill them |
fx, fy |
the focal point, 0 to 1, from the image field; the crop keeps it in view |
f |
webp (default), jpeg or png |
Resizing uses the Worker’s IMAGES binding (Cloudflare Images). Without that binding, or on an account where Images is not available, the route serves the image as it was uploaded, at full size, so pages never show a broken image. The response says which: x-cms-image: transformed, or x-cms-image: original with the reason in x-cms-image-reason.
Files outside public/ are never served here, whatever the request.
Caching
Section titled “Caching”Every delivery response is cached in the Workers Cache API for 10 seconds and carries x-cms-cache: hit or miss. A publish purges the cached document in the data center it is handled in; elsewhere a cached response is served until it expires, so a change is visible everywhere within 10 seconds of reaching the bucket.
The website SDK
Section titled “The website SDK”@tapedb/cms/delivery reads the routes with types taken from your content types. It needs only fetch, so it runs in browsers, Workers, Node, Deno and static-site builds, and it holds no credentials.
import { createDelivery, toHtml, toText } from "@tapedb/cms/delivery";import { content } from "./cms.content";
const site = createDelivery({ url: "https://<worker>.workers.dev", workspace: "<workspace id>", types: content.types,});
const post = await site.bySlug("post", "hello-world", { expand: ["author"] });post?.title; // string | nullpost?.author?.name; // the referenced author, expandedtoHtml(post?.body); // escaped HTMLtoText(post?.body); // plain text, for excerpts and meta descriptionssite.image(post?.cover, { width: 1200, height: 630 }); // a URL, cropped around the focal point
const page = await site.list("post", { where: { section: "News" }, order: "-publishOn", limit: 10 });page.items; page.total; page.cursor;
for await (const p of site.all("post")) { // every published post, page by page}| Method | Returns |
|---|---|
get(type, id, { expand }) |
the published document, or null |
bySlug(type, slug, { expand }) |
the published document, or null |
list(type, { where, order, limit, cursor, expand }) |
{ items, total, cursor } |
all(type, { where, order, expand }) |
an async iterable over every page |
image(value, { width, height, format }) |
the /img URL for an image field |
Field names, where values and order are checked against your content types by TypeScript, and results are typed: a select field is its union of options, an expanded reference is the referenced type. Other failures throw a DeliveryError with status and code. createDelivery also takes fetch, to use a service binding or a mock.
toHtml escapes all text and drops links other than http(s), mailto and same-site paths; external links get rel="noopener". { linkAttributes } adds attributes to every link, such as { rel: "nofollow" }.
@tapedb/cms/react renders rich text and images:
import { Image, RichText } from "@tapedb/cms/react";
export function Article({ post }) { return ( <article> <h1>{post.title}</h1> <Image site={site} image={post.cover} width={1200} height={630} /> <RichText doc={post.body} components={{ blockquote: (node, children) => <aside className="pull-quote">{children}</aside> }} /> </article> );}<Image> takes the alternative text from the field (or alt), requests the size you give it, and loads lazily. <RichText> renders the same nodes as toHtml, with the same link rules; components replaces how a node type renders, receiving the node and its rendered children.
Bindings
Section titled “Bindings”| Binding | For | Without it |
|---|---|---|
CONTENT (R2) |
the delivery path | the studio works; /content answers 501 content_binding_missing, and changes are skipped rather than retried |
IMAGES (Cloudflare Images) |
resizing in /img |
images are served as uploaded |
tapedb add @tapedb/cms writes both into wrangler.jsonc, and tapedb deploy creates the bucket.