Skip to content

Setting Up TinaCMS and Cloudflare Workers for a Next.js Site: The Complete Wiring

Every file and every account screen, in order: a Next.js project with TinaCMS, the Cloudflare adapter, Tina Cloud's Git authoring and tokens, Workers Builds and its variables, then the owner's first save on the live site.

Cover: a chain from the Next.js project to Tina Cloud, the GitHub repository, Workers Builds and the live site, beside the live hero of a logistics site

From an empty folder to the owner's first save

This part wires the whole stack from Part 1, in the order it goes together: the Next.js project and its packages, TinaCMS in the code, the Next.js settings Cloudflare needs, a local check in Cloudflare's runtime, Tina Cloud, Cloudflare Workers Builds, and finally the live editor. Every file below is the working file from the example site, a one-page site for a logistics company, trimmed only where a pattern repeats.

Two accounts come into it, Tina Cloud and Cloudflare, plus the GitHub repository that both of them read.

1. The Next.js project and its packages

bash
npx create-next-app@latest my-site --js --app --tailwind --eslint --no-src-dir --import-alias "@/*" --use-npm --yes
cd my-site
npm i tinacms
npm i -D @tinacms/cli @opennextjs/cloudflare wrangler

Next.js 16's starter turns on cacheComponents and partialPrefetching in next.config.mjs. Both come out in step 3, since Cloudflare's runtime hangs on Cache Components.

The scripts in package.json:

json
{
  "scripts": {
    "dev": "tinacms dev -c \"next dev -p 3005\"",
    "build": "tinacms build --noTelemetry && next build",
    "cf:build": "opennextjs-cloudflare build",
    "cf:deploy": "opennextjs-cloudflare deploy",
    "build:local": "tinacms build --local --skip-cloud-checks -c \"NODE_ENV=production next build\"",
    "start": "next start",
    "lint": "eslint"
  }
}
  • dev starts Tina's local servers, then the Next.js dev server on port 3005, with the editor at localhost:3005/admin.
  • build is what every host runs: tinacms build checks the schema against Tina Cloud and generates the client, then next build builds the site. --noTelemetry keeps the CLI's usage reports off.
  • cf:build and cf:deploy are the Cloudflare adapter's commands, the same ones Workers Builds runs.
  • build:local builds for production against the content on disk, for testing before Tina Cloud exists. The NODE_ENV=production inside it matters; Part 3 shows the error it prevents.

The lines to add to .gitignore:

.env*
# generated from tina/config.js on every dev and build run
/public/admin
/tina/__generated__
# Cloudflare adapter and Wrangler output
/.open-next
/.wrangler
.dev.vars*

2. TinaCMS in the code

The schema: tina/config.js

The schema names every field the owner edits. The example holds the whole page in one document, one JSON file, with each section as an object field. Two sections show every pattern the rest repeat:

javascript
import { defineConfig } from "tinacms";

// The branch Tina Cloud saves to.
const branch = process.env.GITHUB_BRANCH || "main";

const textarea = { component: "textarea" };

// A heading in two tones: the title, then the part shown in the brand colour.
const heading = [
  { type: "string", name: "eyebrow", label: "Small label above" },
  { type: "string", name: "title", label: "Heading" },
  { type: "string", name: "highlight", label: "Heading, coloured part" },
];

// Label each card in a list by one of its own fields.
const listLabel = (field) => ({ itemProps: (item) => ({ label: item?.[field] }) });

export default defineConfig({
  branch,
  clientId: process.env.NEXT_PUBLIC_TINA_CLIENT_ID,
  token: process.env.TINA_TOKEN,

  build: { outputFolder: "admin", publicFolder: "public" },

  // Uploads from the editor land in public/images.
  media: { tina: { mediaRoot: "images", publicFolder: "public" } },

  schema: {
    collections: [
      {
        name: "page",
        label: "Page",
        path: "content",
        format: "json",
        ui: {
          // One page: the editor opens it; adding and deleting stay off.
          allowedActions: { create: false, delete: false },
          router: () => "/",
        },
        fields: [
          {
            type: "object",
            name: "hero",
            label: "Hero",
            fields: [
              {
                type: "object",
                name: "slides",
                label: "Slides",
                list: true,
                ui: listLabel("eyebrow"),
                fields: [
                  ...heading,
                  { type: "string", name: "text", label: "Text", ui: textarea },
                  { type: "image", name: "image", label: "Background image" },
                ],
              },
              { type: "string", name: "primaryButton", label: "Main button" },
              { type: "string", name: "secondaryButton", label: "Second button" },
            ],
          },
          {
            type: "object",
            name: "about",
            label: "About",
            fields: [
              ...heading,
              { type: "string", name: "text", label: "Text", ui: textarea },
              { type: "image", name: "image", label: "Picture" },
              {
                type: "object",
                name: "figures",
                label: "Figures",
                list: true,
                ui: listLabel("label"),
                fields: [
                  { type: "string", name: "value", label: "Figure" },
                  { type: "string", name: "label", label: "Label" },
                  {
                    type: "string",
                    name: "icon",
                    label: "Icon",
                    options: [
                      { value: "truck", label: "Truck" },
                      { value: "forklift", label: "Forklift" },
                      { value: "genset", label: "Genset" },
                      { value: "container", label: "Container" },
                    ],
                  },
                ],
              },
            ],
          },
          {
            type: "object",
            name: "contact",
            label: "Contacts and footer",
            fields: [
              { type: "string", name: "phones", label: "Phone numbers", list: true },
              { type: "string", name: "email", label: "Email" },
              { type: "string", name: "footerText", label: "Footer line", ui: textarea },
            ],
          },
        ],
      },
    ],
  },
});

The services, industries, process and call-to-action sections follow the same shapes: a heading, a text, and a list of cards with a name, a line and a picture.

The content file: content/home.json

json
{
  "hero": {
    "slides": [
      {
        "eyebrow": "Transport Services",
        "title": "Cargo moved",
        "highlight": "Arriving safely and on time.",
        "text": "Full and part loads by road, delivered promptly and safely to their destination.",
        "image": "/images/hero-transport.jpg"
      }
    ],
    "primaryButton": "Get a Quote",
    "secondaryButton": "Explore Our Services"
  },
  "about": {
    "eyebrow": "About us",
    "title": "Moving cargo,",
    "highlight": "powering sites.",
    "figures": [
      { "value": "1200+", "label": "Trips a year", "icon": "truck" },
      { "value": "40+", "label": "Forklifts on lease", "icon": "forklift" }
    ]
  },
  "contact": {
    "phones": ["+000 000 000 000"],
    "email": "hello@example.com"
  }
}

Reading the content: app/page.js

javascript
import client from "@/tina/__generated__/client";
import Home from "@/components/home";

// One static page: the content is read at build time, and each content commit
// rebuilds the site. In development every request reads it fresh.
export default async function Page() {
  const res = await client.queries.page({ relativePath: "home.json" });
  return <Home data={res.data} query={res.query} variables={res.variables} />;
}

Live editing: the client component

javascript
"use client";

import { useTina } from "tinacms/dist/react";
import Hero from "./hero";
import About from "./about";
import Services from "./services";
import Footer from "./footer";

export default function Home(props) {
  const { data } = useTina(props);
  const page = data.page;
  return (
    <main>
      <Hero hero={page.hero} />
      <About about={page.about} />
      <Services services={page.services} />
      <Footer contact={page.contact} />
    </main>
  );
}

Click to edit: a section with tinaField

javascript
import Image from "next/image";
import { tinaField } from "tinacms/dist/react";

export default function Services({ services }) {
  if (!services?.items?.length) return null;
  return (
    <section id="services">
      <h2 data-tina-field={tinaField(services, "title")}>{services.title}</h2>
      <p data-tina-field={tinaField(services, "text")}>{services.text}</p>
      {services.items.map((item) => (
        <article key={item.title} data-tina-field={tinaField(item)}>
          <div data-tina-field={tinaField(item, "image")}>
            <Image src={item.image} alt={item.title} width={600} height={400} />
          </div>
          <h3 data-tina-field={tinaField(item, "title")}>{item.title}</h3>
          <p data-tina-field={tinaField(item, "text")}>{item.text}</p>
        </article>
      ))}
    </section>
  );
}

tinaField(item) with a card alone opens that whole card in the sidebar; tinaField(item, "title") opens one field. Part 3 explains what each piece does inside the editor.

Run npm run dev and open localhost:3005/admin: the editor works locally against the file on disk, with zero accounts, and every save shows as a change in git status. Commit tina/tina-lock.json with the code; Tina Cloud reads the schema from it.

Tina's editor at localhost:3005/admin in local mode: a sidebar listing the page's sections from Hero to Contacts and footer, beside the page with a dashed outline around each editable element
Local mode: the editor edits the file on disk, with zero accounts.

3. Next.js settings for Cloudflare

next.config.mjs

javascript
/** @type {import('next').NextConfig} */
const nextConfig = {
  // Cache Components stays off: Cloudflare's runtime hangs on it,
  // and a static page needs none of it.
  images: {
    // Live, Tina Cloud serves the editor's pictures from its own image server.
    remotePatterns: [{ protocol: "https", hostname: "assets.tina.io" }],
  },
};

export default nextConfig;
  • cacheComponents and partialPrefetching from the starter are removed. Any "use cache" and cacheLife in pages go with them; a plain async page is prerendered at build time all the same.
  • images.remotePatterns lists assets.tina.io. Locally, image fields hold /images/… paths; on the live site Tina Cloud returns them as https://assets.tina.io/<clientId>/…, and next/image answers 400 for any host missing from this list.

wrangler.jsonc

json
{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "my-site",
  "main": ".open-next/worker.js",
  "compatibility_date": "2026-11-01",
  "compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
  "assets": { "directory": ".open-next/assets", "binding": "ASSETS" },
  "images": { "binding": "IMAGES" }
}

The name becomes the Worker's name and its address, <name>.<subdomain>.workers.dev. The ASSETS binding serves the built files, and the IMAGES binding gives next/image Cloudflare's image resizing.

open-next.config.ts

typescript
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
import staticAssetsIncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/static-assets-incremental-cache";

// A static site: pre-built pages are served from Cloudflare's static file storage.
export default defineCloudflareConfig({ incrementalCache: staticAssetsIncrementalCache, enableCacheInterception: true });

The file name is fixed: Workers Builds looks for open-next.config.ts in the project root.

4. A local check in Cloudflare's runtime

Before any account exists, the site runs locally in workerd, the runtime Cloudflare uses:

bash
npx opennextjs-cloudflare build
npx opennextjs-cloudflare populateCache local
npx wrangler dev

opennextjs-cloudflare build runs the project's npm run build, and that runs tinacms build, which wants Tina Cloud's two values. For a check before Tina Cloud, point the build script at the build:local command for the run. Wrangler emulates both bindings locally, image resizing included, and prints the local address.

5. Tina Cloud, screen by screen

1. Sign up at app.tina.io, with an email or with GitHub.

2. Set up Git Authoring. Choose Act as bot: saves are committed by tinacloud-app[bot], which keeps editors' commits apart from developers'. Act as self commits as the account holder and falls back to the bot where permissions run short.

3. Co-authoring. A name and an email that Tina adds to each commit as co-author. A GitHub noreply address (<id>+<username>@users.noreply.github.com) keeps a personal email out of the repository's history. Both settings stay editable later under the account's GitHub Authoring and Co-authoring settings.

Tina Cloud's GitHub Authoring settings with Act as the bot selected, and Co-authoring switched on with a name and a hidden email
Act as the bot keeps editors' saves apart from developers' commits.

4. Authorize with GitHub. GitHub shows "TinaCloud App by Tina wants access to your GitHub account", asking to verify the identity, know which resources the account can reach and act on its behalf. Authorize, then install the app on Only select repositories and pick the site's repository.

GitHub's screen for authorizing the TinaCloud App, listing identity, resources and acting on the account's behalf, with Authorize and Cancel
The grant to Tina's GitHub app, then limited to the one repository.

5. Import an Existing Project. Connect Repo lists the granted repository; select it. Project Configuration asks for:

  • Project Name, which editors see on the login screen;
  • Site URL(s), the comma-separated origins where /admin may log in, http://localhost:3005 for now, with the live address added after the first deploy;
  • Use a separate content repo, off;
  • Advanced Settings, left as they are, with the Tina folder at the root and the branch main, then Create Project.
Tina Cloud's Project Configuration form with the project name, Site URL(s) set to http://localhost:3005, the separate content repo switch off and a Create Project button
Site URL(s) starts with the local address; the live one joins after the first deploy.

6. Overview. The project page shows the Client ID and a four-step checklist: create the project, set up the schema, log in through your site, create a commit. After creation two of the four are ticked.

A Tina Cloud project overview with its Client ID hidden, the site URL http://localhost:3005 and a setup checklist at 2 of 4
The overview: the Client ID and the four-step checklist.

7. Tokens. Tina Cloud creates a Content (Readonly) token for all branches and a Search token. The read-only token is the build's TINA_TOKEN. The Client ID is public, since it ships in the site's code; the token stays private.

Tina Cloud's Tokens page with a Content (Readonly) token and a Search token, both values hidden
The read-only token becomes the build's TINA_TOKEN.

6. Cloudflare Workers Builds, screen by screen

1. Sign up at dash.cloudflare.com on the free plan and verify the email. The domain comes later, in section 7.

2. Rename the workers.dev subdomain first. Workers & Pages, under Compute in the sidebar, shows Account details on the right with Subdomain set to the sign-up email's name. The pencil renames it. Every address the account hands out carries it, so a brand name belongs there before the first deploy.

Cloudflare's Workers & Pages screen with an empty application list, a Create application button, the day's usage at 0 of 100,000 requests, and Account details with the account ID and subdomain hidden
Account details holds the workers.dev subdomain, renamed with the pencil beside it.

3. Create application. "Make something new" offers Connect GitHub, Connect with GitLab, Start with Hello World, Select a template and Upload your static files. Connect GitHub installs Cloudflare's GitHub app; give it the one repository.

Cloudflare's Make something new screen with Connect GitHub, Connect with GitLab, Start with Hello World, Select a template and Upload your static files
Connect GitHub links the repository.

4. Select a repository, then Next.

5. Set up your application:

  • Project name, which becomes <name>.<subdomain>.workers.dev;
  • Build command npx opennextjs-cloudflare build;
  • Deploy command npx opennextjs-cloudflare deploy;
  • Preview command npx opennextjs-cloudflare upload, for builds of other branches;
  • Enable Preview builds, off to keep build minutes for the production branch;
  • Protect with Cloudflare Access, off for a public site.
Cloudflare's Set up your application screen with the project name, npx opennextjs-cloudflare build as the build command, the deploy and upload commands, and preview builds switched off
The adapter's three commands, with preview builds off.

6. Advanced settings:

  • Path /;
  • API token, Create new token, which Cloudflare names after the project;
  • Variables, two pairs through "+ Add variable": NEXT_PUBLIC_TINA_CLIENT_ID with the Client ID, and TINA_TOKEN with the read-only token and Encrypt ticked. An encrypted value stays hidden once saved.
  • Both are build variables, because the build command runs npm run build, and tinacms build reads both while building. Then Deploy.
Advanced settings with the path /, Create new token for the API token, and fields for a variable's name and value with an Encrypt option
Advanced settings: the API token and the build variables.

7. The build page. After "Setting up your repository", the page shows the build settings, a stage bar (Initializing, Cloning, Installing, Building, Deploying) and a live log with Download log and Copy build log. A failed build is fixed by a commit: each push to the production branch starts the next build by itself.

A Workers Builds page for a build in progress, with its build settings, the stage bar from Initializing to Deploying and the live log
The build page: settings, stages and the live log.

A successful deploy log ends like this:

Uploaded 154 of 154 assets
Total Upload: 5032.47 KiB / gzip: 1254.29 KiB
Worker Startup Time: 35 ms
Your Worker has access to the following bindings:
  env.IMAGES    Images
  env.ASSETS    Assets
Deployed my-site triggers
  https://my-site.<subdomain>.workers.dev
Success: Deploy command completed
Success! Build completed.

7. The client's domain

Once the site is approved on its workers.dev address:

  1. Add a domain on the free plan; Cloudflare scans and copies the existing DNS records.
  2. Check the mail records line by line (MX, the SPF and DKIM TXT records, any autodiscover entries) so they still point at the current mail host and email keeps flowing.
  3. At the registrar, swap the two nameservers for the pair Cloudflare shows.
  4. In the Worker: Settings, Domains & Routes, add the bare domain and www as Custom Domains.
  5. To retire the workers.dev address, set "workers_dev": false in wrangler.jsonc.

8. Closing the loop

  1. In the Tina Cloud project, add the live address to Site URL(s): http://localhost:3005, https://my-site.<subdomain>.workers.dev, plus the custom domain once it is live.
  2. Open https://my-site.<subdomain>.workers.dev/admin and log in with the Tina Cloud account. The live page loads in the editor, the sidebar lists the sections, and every editable element carries its dashed outline.
  3. Edit, then Save. Within seconds a commit by tinacloud-app[bot] with the message "TinaCMS content update" lands on main.
  4. That commit starts a Workers Build, and the build deploys the change.
  5. Invite the owner from the project's Collaborators page. The owner logs in at /admin with an email and password; GitHub stays out of sight. The free plan covers two editors.
The live site open in Tina's editor: a sidebar listing Hero, About, Services, Industries, How it works, Get in touch and Contacts and footer, beside the page with dashed outlines on its headings, text and figures
The live site in the editor, ready for the owner's first save.

9. Day to day

  • Owners edit several sections and save once: one commit, one build.
  • Developers pull before working, since owners' saves land on main as commits, and push changes in batches, since each push is a build.
  • Running costs: Tina Cloud free for two editors, GitHub free, Cloudflare free with 3,000 build minutes a month, and the domain's yearly renewal.

The series

Websites & AppsSites, stores and web apps on Shopify, Framer, Webflow or custom code, integrations with CMS, CRM and more, servers, and security.

Sources

Published
Author
Simon Booban

Resources

More episodes

View all

Ready when you are

Tell us what you need and a written quote comes back within a working day.

Phone or WhatsApp
Services

By sending, you agree to our Privacy Policy and Terms.

or connect with us via:
WhatsAppEmail