Skip to content

Bind the API Worker for server-side calls - #452

Merged
neuromechanist merged 6 commits into
stagingfrom
feature/issue-449-wire-api-binding
Oct 12, 2026
Merged

neuromechanist merged 6 commits into
stagingfrom
feature/issue-449-wire-api-binding

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Part of #449. Follows #450. nemar-cli#1710 (the API side) is merged to dev; this waits only for its deploy to nemar-api-dev before it merges to staging.

What changes

  • wrangler.test.toml: [[services]] API -> nemar-api-dev, the Worker behind api-test.nemar.org. deploy-test.yml swaps this file into wrangler.toml, so it applies to test.nemar.org.
  • wrangler.toml: [[services]] API -> nemar-api, the Worker behind api.nemar.org. Previews are left without a binding on purpose (services are not inherited into [env.preview], and a branch build runs unreviewed code that must not be able to name a visitor at the production API). Wrangler warns about the missing restatement; the comment says to leave the warning.
  • src/middleware.ts: a production host (nemar.org, www, ww2, app) whose project has no API binding logs one warning per isolate, the way EMBED_ANALYTICS does, because the site would otherwise work and quietly stay in the API's shared pool. Staging has a binding but is not a production host, so a missing binding there is not warned about.
  • test/wrangler-bindings.test.ts: production names nemar-api, staging names nemar-api-dev, and neither file restates services under env.preview.
  • ADR 0026, the changelog, AGENTS.md (promotion gate and wrangler pages dev note), .rules/astro.md (manual staging deploys) and the handoff say all of this.

Order

  1. nemar-cli dev deployed to nemar-api-dev (the Deploy Backend run for the #1710 merge). This PR is then merged to staging, which deploys test.nemar.org with the binding.
  2. Read the [api-fetch] lines on test.nemar.org. The development API bypasses its limiter and sends no rate-limit headers, so the line to expect is the warning that an answer carried none. It shows the binding applied (the watching runs only for calls over a binding) and nothing about the visitor's address.
  3. nemar-cli released to main and deployed to nemar-api. Only then is the staging to main release of the website promoted (the gate is in AGENTS.md step 8 and the handoff), so production never has the binding in front of an API that does not read the visitor.
  4. After the release, check on nemar.org: X-RateLimit-Bucket: site-ip with a falling X-RateLimit-Remaining across two calls, and the [api-fetch] first-call line in the production deployment's tail (site-ip, info).

Testing

  • Middleware tests: each production host (nemar.org, app, www, ww2) warns on its first request; a repeat does not; test.nemar.org, a *.pages.dev preview and localhost say nothing; a production host with a binding says nothing. Mutants of the condition (app host only, apex only, no www or ww2, wrong host class, no once-flag) are killed.
  • test/wrangler-bindings.test.ts: three tests, each killed by swapping the Worker names or restating services under env.preview.
  • bun run lint, typecheck (0 errors), test (3365 pass).
  • Two Sonnet reviewers' findings (a test that did not cover every host, wording about staging, the staging expectation, the promotion gate living only in this body, the manual-deploy and wrangler pages dev notes, the edge-protection clause in the ADR) are fixed here.
  • CI, then the checks under Order on test.nemar.org and nemar.org.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

@neuromechanist
neuromechanist marked this pull request as ready for review October 12, 2026 19:58
@neuromechanist
neuromechanist merged commit d23d327 into staging Oct 12, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-449-wire-api-binding branch October 12, 2026 19:58
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