Repository navigation
Send the news reads over the API binding - #456
Merged
Merged
Conversation
Deploying nemar-website with
|
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 globalfetch, on the reasoning that a server caller "can passapiFetchas theirfetchoption"; 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 onfetchworks, and the first-call report inapiFetchis satisfied by any one site that is counted per visitor.What changed
src/lib/news-api.ts: thefetchoption is typed as a URL string and a plainRequestInit, which is all the module passes, soapiFetchfits without an adapter andfetchstill fits. The module keepsfetchas its default because the news editor runs it in the browser, where it cannot importapiFetch(test/client-bundle-guard.test.ts).fetch: apiFetch: the news column on/(listNews),/news(listNews) and/news/<slug>(getNewsPostand the "more news"listNews).fetch: apiFetch:/news/feed.xml(listNews),/sitemap.xml(listAllNews) and/og/news/<slug>.png(getNewsPost).test/routes/api-binding-call-sites.test.tscovers all six, with the first-call report inapi-fetch.tsuntouched. The three routes run under the recording binding withglobalThis.fetchas a tripwire. The three.astropages have no rendering harness here, so a source-level guard reads every caller oflistNews,listAllNewsandgetNewsPostinsrcand fails on one that does not passfetch: apiFetchor does not import it. It also names the six call sites that exist today, so a scan that quietly found nothing fails too.Update, 2026-10-12section 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,
apiFetchomits the header and logs at most once a minute; for the feed, the sitemap and the card the visitor is the crawler, whose ownCF-Connecting-IPis the address that is forwarded, which is the right party to count. Outside a request context (none of these six runs there)apiFetchis a plainfetch.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,
/newsand a post answer 503 withno-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
isPngcheck in the card route is aHEADfor the site's own/og/news-card/file, not the API, so it stays a plainfetch./admin/newsand/admin/news/<id>(listAdminNews,getAdminNewsPost), the other authenticated clients and the data and Zarr clients are outside this change; ADR 0026 leaves them onfetchand 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 passesbiome check).bun run build: completes. The build rewrites the trackedpublic/og-image.png; that was reverted and is not in this diff.origin/stagingtext one at a time madeapi-binding-call-sites.test.tsfail 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 thegetNewsPostcall in[slug].astrofailed it naming that call. With nothing reverted it passes.Could not verify
.astropages are checked by the source-level guard and the build, not rendered with a binding.test.nemar.orgis bound tonemar-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-ipand a fallingX-RateLimit-Remaining) is confirmed only on nemar.org after the production release.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-Forbefore a release carrying the binding is promoted tomain, as the changelog already says for #449. This pull request targetsstagingand does not start any release.Refs #449