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.
-
Put rows in the real database.
Terminal pnpm db:seed:remote --with-images --with-faviconsSeeds the
ai-toolsdemo dataset;--dataset <name>for another,--from <dir>for any directory of listing files (a copy’s oldsrc/content/listings/, for one). A re-run replaces only its own rows, and--dry-runonly prints the SQL.--with-imagesstores each listing’s ownhttps://logo and then the dataset’s/logos/files in R2;--with-faviconsfetches the icon each remaining site publishes. A spreadsheet goes in withpnpm listings:import my-data.csv --remoteinstead.db:seed — seed/datasets/ai-tools/listings → D1 (remote)stored N dataset logo URL(s) in R2 in 40sfetched N favicon(s) into R2 in 90s (no icon: unreachable=N)uploaded N /logos/ file(s) to R2N listing(s), N click row(s) in N statement(s); largest N bytes (limit 90000)seeded N listing(s) into the remote database -
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.
-
Set the three variables where the build runs.
Variable Value CLOUDFLARE_ACCOUNT_IDthe account id pnpm exec wrangler whoamiprintsD1_DATABASE_IDdatabase_idinwrangler.jsoncD1_READ_TOKENthe token from step 2, stored as a secret GitHub Actions: all three into
.env.prod, thenpnpm cf:ci. Workers Builds: Workers & Pages → your Worker → Settings → Build → Variables and secrets; all three are build-time variables. -
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).envis gitignored.pnpm previewthen shows what the live site would. Clear the three again to go back to the local database. -
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 namingD1_READ_TOKENor another of the three means the variables never reached it. -
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/reportsproviders.rebuild is "none": approved listings stay off the site until someone publishes.
Verify
Section titled “Verify”| 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 |
Worth knowing
Section titled “Worth knowing”- 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_TOKENis a build secret: not a Workers Builds or GitHub Actions deploy token, and never namedCLOUDFLARE_API_TOKEN.- Set
media.baseUrlto the bucket’s public host before the first production build; the defaulthttps://media.example.combreaks 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 frompnpm listings:import my-data.csv --remote.
When it is off or degraded
Section titled “When it is off or degraded”| 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.Configuration
Section titled “Configuration”| 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 somesrc/loaders/d1.ts— the REST client, the paging, the retries, the popularity mergesrc/loaders/d1-local.ts— the local database, throughwrangler d1 execute --localsrc/loaders/normalize.ts— one row into the listing shapescripts/seed.ts—pnpm db:seed:localandpnpm db:seed:remote, the three logo passesDirectory
drizzle/— the migrationspnpm cf:setupandpnpm db:migrate:remoteapply- …
.env.example— the three build variables, with commentswrangler.jsonc—database_id, and theMEDIAbucket the seed uploads to