Cloudflare Workers
Workers Assets strips .html, and it broke our Google verification
Google Search Console verifies ownership by fetching a token file at an exact URL. On Cloudflare Workers with static assets, that URL does not exist — even though the file does.
The symptom
Search Console hands you a file called googlef59e5bcb638ff23e.html and tells you to put it at the root of your site. We did. We deployed. Search Console returned a 404.
The file was in dist/. Wrangler had uploaded it. wrangler deploy listed it in the asset manifest. And the URL 404'd.
Why
Workers Assets applies HTML handling before it serves anything. The default, auto-trailing-slash, means an uploaded file named foo.html is served at /foo, and a request for /foo.html redirects or 404s. This is usually what you want: it is how services/index.html becomes the clean URL /services/.
It is not what you want when a third party has told you the exact URL it will fetch, extension included.
Two fixes that made it worse
Changing html_handling globally
Setting html_handling: "none" in wrangler.jsonc does make /googlef59e5bcb638ff23e.html resolve. It also turns /services/ into a 404, because nothing maps the directory to its index.html any more. You would be trading a verification file for every clean URL on the site.
Keeping the file in the build output
Our build copies a whitelist of paths into dist/. Adding the token to that list seemed harmless. It produced a 307 instead of a 404 — marginally different, equally useless. Assets are matched before your Worker's fetch runs, so as long as the file exists as an asset, the asset layer owns that path and redirects it to the extensionless form. The Worker never sees the request.
That is the part worth remembering: an asset at a path takes the path away from your Worker.
The fix
Remove the file from the build entirely, and serve the token from the Worker before falling through to assets. Verification tokens are a few bytes of known text — there is no reason for them to be files at all.
const VERIFICATION_FILES = new Set([
'/googlef59e5bcb638ff23e.html',
]);
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (VERIFICATION_FILES.has(url.pathname)) {
return new Response(`google-site-verification: ${url.pathname.slice(1)}`, {
headers: { 'content-type': 'text/html; charset=utf-8' },
});
}
return env.ASSETS.fetch(request);
},
};
200, correct body, and /services/ still works. Verification passed on the next check.
Leave it there afterwards
Google re-fetches the token periodically and un-verifies the property if it stops resolving. The same is true of Bing and of most platforms that use file-based ownership proof. Deleting it after verification succeeds is a slow-fuse outage you will not connect to the change that caused it.
The general rule
Any time a third party specifies an exact URL — verification tokens, .well-known paths, apple-app-site-association, ACME challenges — do not route it through a static asset pipeline that rewrites paths. Serve it from code, where the path you write is the path that answers.
Stuck on something like this?
Northstar HQ builds and repairs production web software. Fixed price against a fixed scope, and you own the code.
Start a project