A Cloudflare Worker route like app.example.com/* only runs when a request for that hostname reaches Cloudflare. For that, the hostname needs a DNS record in the zone, and the record has to be proxied (the orange cloud). Without one the name doesn't resolve at all, and wrangler deploy still succeeds without a warning. When the Worker is the whole site and there is no origin server, the record to add is a proxied AAAA pointing at 100::. I shipped a subdomain that sat in this state for part of a day, so I made the deploy tooling check that every Worker host has its record.
Why doesn't my Worker route work on a subdomain?
A route tells Cloudflare which Worker should handle requests that already reached Cloudflare for a given hostname and path. It doesn't publish the hostname. DNS does that. For a subdomain with no record, a browser's lookup gets NXDOMAIN (Chrome shows DNS_PROBE_FINISHED_NXDOMAIN), the request never reaches Cloudflare, and the route never gets a chance to match.
The record also has to be proxied. A DNS-only (grey cloud) record sends visitors straight to whatever IP it holds, past Cloudflare's network, so the Worker never sees them.
What happened
My site runs on one Worker with a route per hostname in wrangler.jsonc:
"routes": [
{ "pattern": "www.mohamedgado.com/*", "zone_name": "mohamedgado.com" },
{ "pattern": "mohamedgado.com/*", "zone_name": "mohamedgado.com" },
{ "pattern": "masareef.mohamedgado.com/*", "zone_name": "mohamedgado.com" },
{ "pattern": "rafiq.mohamedgado.com/*", "zone_name": "mohamedgado.com" },
{ "pattern": "nafis.mohamedgado.com/*", "zone_name": "mohamedgado.com" },
{ "pattern": "hadeed.mohamedgado.com/*", "zone_name": "mohamedgado.com" }
]
Each app gets a short install host (hadeed.mohamedgado.com) that the Worker redirects to the right store. When a new iPhone app went live, a commit added its route, its zone rules, the production check and the sitemap entry. It deployed green. The name never resolved.
Two things made it slip through:
- The checklist was stale. The written rule for a new subdomain said "add one CNAME at the registrar". That was true until the zone's DNS moved to Cloudflare a few days earlier. After the move, nothing in the repo created the record.
- Another app already linked to it. A "More from us" row in one of my other apps pointed at the new host, so real users could tap a link that went nowhere.
The fix: a proxied AAAA 100:: record
Cloudflare's docs for Workers routes cover the case where the Worker is the origin: add a proxied AAAA record with the content 100::. 100:: is the IPv6 discard prefix. It's never routed anywhere, so if the proxy were ever turned off, the name would point at nothing instead of at somebody else's server. With the proxy on, Cloudflare answers the request and the route sends it to the Worker.
One record per host, either in the dashboard or with the API:
export const WORKER_PLACEHOLDER = { type: 'AAAA', content: '100::', proxied: true, comment: '[portfolio] Worker route origin placeholder (Vercel retired)' }
await cf(`/zones/${zoneId}/dns_records`, {
method: 'POST',
body: JSON.stringify({ ...WORKER_PLACEHOLDER, name: host, ttl: 1 }),
})
ttl: 1 means "automatic", which is the only TTL a proxied record uses anyway.
Routes or Custom Domains?
Workers also has Custom Domains. Those create the DNS record and the certificate for you, and they're the simpler choice when a Worker owns a whole hostname. Routes are what you use when one Worker answers several hostnames by pattern, or shares a hostname with other things. Routes leave DNS to you. If you use routes, the DNS record is your job, and nothing in the deploy will remind you.
Make the tooling check it
The real fix wasn't the one record. It was making a missing record impossible to ship again. My zone setup script, pnpm cf:zone --production, already applied cache and redirect rules through the Cloudflare API. It now also walks every host the Worker answers and decides what that host's DNS needs:
/** Production hosts the Worker answers through its routes; each needs a proxied DNS record to exist. */
export const WORKER_HOSTS = [HOSTS.production.www, ...Object.values(HOSTS.production.apps)]
/**
* What a Worker host's DNS records need: 'ok', 'create' (none yet), 'proxy' (our placeholder,
* orange cloud off) or 'conflict' (something else lives there; never overwritten, a human decides).
*/
export function workerHostAction(records) {
if (records.length === 0) return 'create'
const ours = records.length === 1 && records[0].type === 'AAAA' && records[0].content === '100::'
if (!ours) return 'conflict'
return records[0].proxied ? 'ok' : 'proxy'
}
The script creates a missing placeholder and turns the proxy back on for one that has it off. It never touches a host that holds anything else: a leftover CNAME to an old host could be a real service, so the script prints CONFLICT, left alone and exits non-zero. A dry run prints would create without changing anything.
WORKER_HOSTS is built from the same host map the routes and the redirects come from, so a new app can't get a route without getting a DNS row. A test checks that, and checks each decision:
test('every Worker host gets a proxied AAAA 100:: placeholder; a missing one is created, a foreign one is never overwritten', async () => {
const { WORKER_HOSTS, workerHostAction } = await import('./zone-rules.mjs')
for (const app of Object.values(HOSTS.production.apps)) assert.ok(WORKER_HOSTS.includes(app), `${app} has no placeholder row`)
assert.ok(WORKER_HOSTS.includes(HOSTS.production.www))
assert.equal(workerHostAction([]), 'create')
assert.equal(workerHostAction([{ type: 'AAAA', content: '100::', proxied: true }]), 'ok')
assert.equal(workerHostAction([{ type: 'AAAA', content: '100::', proxied: false }]), 'proxy')
assert.equal(workerHostAction([{ type: 'CNAME', content: 'cname.vercel-dns.com', proxied: false }]), 'conflict')
})
The dry run found more than DNS
The first dry run against the live zone showed three problems at once: the missing record, the new host's zone rules that had never been applied, and three zone settings that had drifted back to Cloudflare's defaults (early_hints, fonts and automatic_https_rewrites were "on" again). I almost dismissed the drift as default noise. early_hints is off on purpose on this zone, so the repo's value wins and the script set it back.
A subdomain is done when it answers
The rule I wrote down after this: a new Worker subdomain is done when pnpm cf:zone --production prints its host as ok and the production check (pnpm check:prod), which requests every app host and follows its redirect, is green. A merged commit doesn't count, and neither does a green deploy.
Takeaways
- A Worker route doesn't create DNS. Each hostname needs a proxied record, or the name doesn't resolve and the route never runs.
- When the Worker is the origin, use a proxied
AAAA 100::. It points nowhere if the proxy is ever turned off. - Derive the DNS check from the same list as the routes, and let the script create the record instead of a checklist.
- Never let automation overwrite a record it didn't create. Report the conflict and fail.
Top comments (0)