Skip to content

Commit af9865b

Browse files
pirateclaude
andcommitted
Worker: run_worker_first so dynamic / handler actually runs
Cloudflare Workers Static Assets serves exact-match files directly from the edge without invoking the Worker by default. That meant my new /-intercepting handleIndex was never reached for /index.html — CF kept returning the cached static index.html. run_worker_first = true makes every request go through the Worker first; static assets are still served via env.ASSETS.fetch when the Worker dispatches to it. Also adds a console.error in the / fallback path so future silent failures surface in wrangler tail. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 528c69d commit af9865b

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

cloudflare/worker/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export default {
3535
if (url.pathname === "/" || url.pathname === "/index.html") {
3636
try {
3737
return await handleIndex(env, url);
38-
} catch (e) {
38+
} catch (e: any) {
39+
console.error("handleIndex failed:", e?.message, e?.stack);
3940
// Fall through to the static index.html in /public on any error.
4041
}
4142
}

cloudflare/wrangler.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ routes = [
1111
# Static asset binding: serves files in ./public directly. /<username>
1212
# resolves to <username>.html via auto-trailing-slash; misses fall through
1313
# to the Worker code, which renders a "mining…" page for new users.
14+
#
15+
# run_worker_first = true means every request hits the Worker first
16+
# (which can then dispatch to env.ASSETS.fetch for static files). Needed
17+
# for the dynamic / handler — otherwise CF serves the cached static
18+
# index.html from the edge and the Worker never gets invoked.
1419
[assets]
1520
directory = "./public"
1621
binding = "ASSETS"
1722
not_found_handling = "none"
1823
html_handling = "auto-trailing-slash"
24+
run_worker_first = true

0 commit comments

Comments
 (0)