Skip to content

Send the news reads over the API binding - #456

Merged
neuromechanist merged 5 commits into
stagingfrom
fix/news-calls-over-binding
Oct 13, 2026
Merged

neuromechanist merged 5 commits into
stagingfrom
fix/news-calls-over-binding

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

ADR 0026 says every server-only call to the API goes through apiFetch, so the API's rate limiter counts each visitor on their own instead of the site's few shared Cloudflare egress addresses as one client (#449, nemar-cli#1709). The news reads were left on the global fetch, on the reasoning that a server caller "can pass apiFetch as their fetch option"; nothing did. So the home page, which is the most visited landing page, and /news, each post, the RSS feed, the sitemap and the social-card redirect still left from the shared pool, and nothing noticed: a call left on fetch works, and the first-call report in apiFetch is satisfied by any one site that is counted per visitor.

What changed

  • src/lib/news-api.ts: the fetch option is typed as a URL string and a plain RequestInit, which is all the module passes, so apiFetch fits without an adapter and fetch still fits. The module keeps fetch as its default because the news editor runs it in the browser, where it cannot import apiFetch (test/client-bundle-guard.test.ts).
  • Pages pass fetch: apiFetch: the news column on / (listNews), /news (listNews) and /news/<slug> (getNewsPost and the "more news" listNews).
  • Routes pass fetch: apiFetch: /news/feed.xml (listNews), /sitemap.xml (listAllNews) and /og/news/<slug>.png (getNewsPost).
  • test/routes/api-binding-call-sites.test.ts covers all six, with the first-call report in api-fetch.ts untouched. The three routes run under the recording binding with globalThis.fetch as a tripwire. The three .astro pages have no rendering harness here, so a source-level guard reads every caller of listNews, listAllNews and getNewsPost in src and fails on one that does not pass fetch: apiFetch or does not import it. It also names the six call sites that exist today, so a scan that quietly found nothing fails too.
  • ADR 0026 gets an Update, 2026-10-12 section recording that the news reads now pass it (the decision stands), and the changelog gets an entry.

No response shape, status code or caching header changes. When a request has no usable visitor address, apiFetch omits the header and logs at most once a minute; for the feed, the sitemap and the card the visitor is the crawler, whose own CF-Connecting-IP is the address that is forwarded, which is the right party to count. Outside a request context (none of these six runs there) apiFetch is a plain fetch.

One behavior to know: a call over the binding that fails is not retried on the public network (ADR 0026, decision 5). Each of the six already degrades when the API does not answer (the home column hides, /news and a post answer 503 with no-store, the feed answers 503, the sitemap drops the posts, the card redirect falls back to whatever card exists), so an outage looks as it did.

What the nemar-cli release changes

nemar-cli 0.10.17, which is releasing next, makes the API Worker count a request that reaches it without a client address by the visitor its caller forwards in X-Forwarded-For, in a per-visitor bucket (nemar-cli ADR 0098). Until a server call goes over the service binding it carries the shared address, so none of that applies to it; after this change these six do.

Not changed

  • The isPng check in the card route is a HEAD for the site's own /og/news-card/ file, not the API, so it stays a plain fetch.
  • /admin/news and /admin/news/<id> (listAdminNews, getAdminNewsPost), the other authenticated clients and the data and Zarr clients are outside this change; ADR 0026 leaves them on fetch and its new update says so.

Verification

  • bun run test: 136 files passed, 3366 tests passed, 7 skipped.
  • bun run typecheck: 0 errors. bun run lint: clean (the new test file also passes biome check).
  • bun run build: completes. The build rewrites the tracked public/og-image.png; that was reverted and is not in this diff.
  • The guard fails when a site reverts. On a scratch copy, restoring each of the six files to its origin/staging text one at a time made api-binding-call-sites.test.ts fail every time (the source-level test names the file and call; the feed, sitemap and card also fail their route test), and putting back only the getNewsPost call in [slug].astro failed it naming that call. With nothing reverted it passes.

Could not verify

  • The binding exists only on staging and production, so none of this ran against one end to end. A preview has no binding on purpose (ADR 0026), so its news reads still use the public network.
  • The three .astro pages are checked by the source-level guard and the build, not rendered with a binding.
  • test.nemar.org is bound to nemar-api-dev, which bypasses its limiter, so staging can only show the "no rate-limit headers" warning from the first-call report. The per-visitor keying (X-RateLimit-Bucket: site-ip and a falling X-RateLimit-Remaining) is confirmed only on nemar.org after the production release.
  • I did not merge, so nothing has run on test.nemar.org.

Promotion

The production promotion of the website follows nemar-cli 0.10.17: the production API must be running the change that reads X-Forwarded-For before a release carrying the binding is promoted to main, as the changelog already says for #449. This pull request targets staging and does not start any release.

Refs #449

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 228bc1e
Status: ✅  Deploy successful!
Preview URL: https://dddabfcd.nemar-website.pages.dev
Branch Preview URL: https://fix-news-calls-over-binding.nemar-website.pages.dev

View logs

@neuromechanist
neuromechanist merged commit 74e46dd into staging Oct 13, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the fix/news-calls-over-binding branch October 13, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant