Skip to content
Early bird + Black Friday · 73% off

Get ZeroDirs for $179 $49

Claim $49 deal

The build's database

Every build reads its listings from D1. With no D1 credentials — your machine, CI — it reads the local Miniflare database under .wrangler/state/, the one pnpm dev seeds. With all three of CLOUDFLARE_ACCOUNT_ID, D1_DATABASE_ID and D1_READ_TOKEN — a production builder — it reads the real database over the REST API. There is no third option: a builder without them fails rather than shipping stale data.

Needs pnpm cf:setup and deploys on push — pnpm cf:ci --enable, or Workers Builds.

  1. Put rows in the real database.

    Terminal
    pnpm db:seed:remote --with-images --with-favicons

    Seeds the ai-tools demo dataset; --dataset <name> for another, --from <dir> for any directory of listing files (a copy’s old src/content/listings/, for one). A re-run replaces only its own rows, and --dry-run only prints the SQL. --with-images stores each listing’s own https:// logo and then the dataset’s /logos/ files in R2; --with-favicons fetches the icon each remaining site publishes. A spreadsheet goes in with pnpm listings:import my-data.csv --remote instead.

    db:seed — seed/datasets/ai-tools/listings → D1 (remote)
    stored N dataset logo URL(s) in R2 in 40s
    fetched N favicon(s) into R2 in 90s (no icon: unreachable=N)
    uploaded N /logos/ file(s) to R2
    N listing(s), N click row(s) in N statement(s); largest N bytes (limit 90000)
    seeded N listing(s) into the remote database
  2. Create the read token.

    Cloudflare dashboard → My Profile → API Tokens → Create Token → Create Custom Token; permissions Account → D1 → Read, Account Resources the owning account, nothing else. Continue to summary → Create Token, then copy the value — shown once.

  3. Set the three variables where the build runs.

    Variable Value
    CLOUDFLARE_ACCOUNT_ID the account id pnpm exec wrangler whoami prints
    D1_DATABASE_ID database_id in wrangler.jsonc
    D1_READ_TOKEN the token from step 2, stored as a secret

    GitHub Actions: all three into .env.prod, then pnpm cf:ci. Workers Builds: Workers & Pages → your Worker → Settings → Build → Variables and secrets; all three are build-time variables.

  4. Try it locally first, if you like.

    .env
    CLOUDFLARE_ACCOUNT_ID=<from wrangler whoami>
    D1_DATABASE_ID=<database_id from wrangler.jsonc>
    D1_READ_TOKEN=<the token from step 2>
    Terminal
    pnpm build
    [zerodirs-d1] D1 (remote): N approved listings (featured N, 30-day clicks for N, N REST requests)

    .env is gitignored. pnpm preview then shows what the live site would. Clear the three again to go back to the local database.

  5. Push, then read the deploy’s build log.

    Workers & Pages → your Worker → Deployments → that build’s log, or the Actions build step. [zerodirs-d1] D1 (remote): … is the line you want; a failure naming D1_READ_TOKEN or another of the three means the variables never reached it.

  6. Turn on publishing on approval.

    site.config.ts
    providers: { rebuild: 'deploy-hook', rebuildAuto: true },

    Publishing on approval has the hook URL and the GitHub alternative. Until then /admin/ reports providers.rebuild is "none": approved listings stay off the site until someone publishes.

Where You should see
The loader the build log [zerodirs-d1] D1 (remote): N approved listings (…) on the builder; D1 (local) on your machine
The count the home page hero, N tools across M categories, against the database the same N as the operator’s query: pnpm exec wrangler d1 execute DB --remote --command "SELECT count(*) FROM listings WHERE status='approved' AND slug IS NOT NULL"
A seeded logo a seeded listing’s page, the logo’s src https://<your media host>/logos/<id>.<ext> in a production build — the R2 key on media.baseUrl; /media/logos/<id>.<ext>/ in a local one
  • Put the three credentials where the build runs. A builder without them has no local database and fails on the first missing one; the previous deploy stays live, and nothing stale ever ships as a success.
  • All three or none. One or two fail the build with … is set but … is not set.
  • A wrong token or database id fails on a line beginning D1 REST, carrying the status code.
  • D1_READ_TOKEN is a build secret: not a Workers Builds or GitHub Actions deploy token, and never named CLOUDFLARE_API_TOKEN.
  • Set media.baseUrl to the bucket’s public host before the first production build; the default https://media.example.com breaks every logo, unwarned. A local build links logos through /media/ and does not need it.
  • Logo passes need an R2 bucket bound as MEDIA: wrangler.jsonc has no r2_buckets entry bound as MEDIA; --with-images needs one.
  • Rows also arrive by approving a submission in /admin/, or from pnpm listings:import my-data.csv --remote.
The three credentials The build
none set reads the local database; the message below when that database has never been migrated
all three set reads the real database
one or two set fails: listings loader: CLOUDFLARE_ACCOUNT_ID, D1_DATABASE_ID are set but D1_READ_TOKEN is not set. …
listings loader: the local database has no listings table (no such table: listings: SQLITE_ERROR). Locally, run `pnpm dev` once (it applies the migrations and seeds the demo data), or `pnpm db:migrate:local && pnpm db:seed:local`. A builder (Workers Builds, GitHub Actions) has no local database and needs CLOUDFLARE_ACCOUNT_ID, D1_DATABASE_ID and D1_READ_TOKEN as build variables to read the real one.
Field What it changes Reference
media.baseUrl the host every logo_key is served from in a production build; the only site.config.ts field this page needs media
CLOUDFLARE_ACCOUNT_ID, D1_DATABASE_ID, D1_READ_TOKEN which database the build reads; build variables, not config Build-time variables
providers.rebuild, providers.rebuildAuto what an approval triggers providers
  • src/loaders/index.ts — which database: the real one with the three credentials, the local one with none, a failure with some
  • src/loaders/d1.ts — the REST client, the paging, the retries, the popularity merge
  • src/loaders/d1-local.ts — the local database, through wrangler d1 execute --local
  • src/loaders/normalize.ts — one row into the listing shape
  • scripts/seed.ts — pnpm db:seed:local and pnpm db:seed:remote, the three logo passes
  • Directorydrizzle/ — the migrations pnpm cf:setup and pnpm db:migrate:remote apply
    • …
  • .env.example — the three build variables, with comments
  • wrangler.jsonc — database_id, and the MEDIA bucket the seed uploads to