Skip to content

Fix: keep /api/notices on both hosts - #182

Merged
neuromechanist merged 1 commit into
mainfrom
fix/issue-181-notices-host-neutral
Jul 25, 2026
Merged

neuromechanist merged 1 commit into
mainfrom
fix/issue-181-notices-host-neutral

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #181. Follow-up to #179.

The site-wide notice banner never rendered on app.nemar.org.

The bug

/api/notices wasn't in APP_ROUTE_PREFIXES, so the middleware classified it marketing-only and 301'd it off the app host:

$ curl -o /dev/null -w '%{http_code} -> %{redirect_url}' https://app.nemar.org/api/notices
301 -> https://ww2.nemar.org/api/notices

SiteNotices.astro fetches that path same-origin. On the app host the redirect is cross-origin, ww2.nemar.org sets no CORS headers, so the fetch rejects and the banner renders nothing. Even with CORS, credentials: "same-origin" would drop the cookie across the origin boundary and the request would arrive anonymous.

Net effect: no notice displayed to any signed-in user on the app host — dashboard, upload, settings, admin — including scope: "admins" and scope: "members" notices, which are the only ones that require a session. The role-scoped half of the feature was unreachable.

Not user-visible yet: production has zero notices, so nothing was being hidden. It needed fixing before the first one is posted.

Why it slipped through

Route classification is binary — a path is either an app route or a marketing route, and anything on the "wrong" host gets 301'd. There was no way to express "serves correctly on both", which is what a public JSON feed consumed by chrome on every page of both hosts requires. I verified the marketing host in QA and reasoned the app host was covered by the same code, which was the wrong assumption to leave untested.

The fix

HOST_NEUTRAL_ROUTE_PREFIXES + isHostNeutralRoute, checked in getCrossHostRedirect before the app/marketing decision. /api/notices is its only member. The binary model is untouched for everything else.

/api/v1 and /api/auth deliberately stay app-only — their whole point is the Domain=app.nemar.org cookie scope. /api/notices is different: public, works with or without a session, and forwards whatever cookie the request already carries same-origin (which is how an admin on the app host gets their admins-scoped notices).

Testing

851 tests passing (5 new). typecheck, lint, build clean.

New coverage in host.test.ts:

  • /api/notices returns null from getCrossHostRedirect on both hosts, with and without a query string
  • prefix matching doesn't over-reach — /api/notices-admin and /api/v1/notices are not host-neutral
  • regression guard that /api/v1/* and /api/auth/* still redirect to the app host, since neutralising those would break the session cookie

Worth stating plainly: I could not reproduce the two-host behaviour end-to-end locally — astro dev rejects a spoofed Host header with a 403 before middleware runs. The unit tests exercise getCrossHostRedirect directly with real two-host URLs, and I confirmed it is the only cross-host redirect path in middleware.ts (the other is getRetiredRedirect, which only maps /docs and /citation-dashboard). The end-to-end check belongs on the preview deploy or post-merge against app.nemar.org.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 2983776 into main Jul 25, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the fix/issue-181-notices-host-neutral branch July 25, 2026 16:44
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.

Notice banner never renders on app.nemar.org (/api/notices 301s cross-origin)

1 participant