Repository navigation
Fix: keep /api/notices on both hosts - #182
Merged
Merged
Conversation
Deploying nemar-website with
|
| Latest commit: |
da3bc67
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3e4c4df4.nemar-website.pages.dev |
| Branch Preview URL: | https://fix-issue-181-notices-host-n.nemar-website.pages.dev |
This was referenced Jul 25, 2026
Merged
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.
Closes #181. Follow-up to #179.
The site-wide notice banner never rendered on
app.nemar.org.The bug
/api/noticeswasn't inAPP_ROUTE_PREFIXES, so the middleware classified it marketing-only and 301'd it off the app host:SiteNotices.astrofetches that path same-origin. On the app host the redirect is cross-origin,ww2.nemar.orgsets 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"andscope: "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 ingetCrossHostRedirectbefore the app/marketing decision./api/noticesis its only member. The binary model is untouched for everything else./api/v1and/api/authdeliberately stay app-only — their whole point is theDomain=app.nemar.orgcookie scope./api/noticesis 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 theiradmins-scoped notices).Testing
851 tests passing (5 new). typecheck, lint, build clean.
New coverage in
host.test.ts:/api/noticesreturns null fromgetCrossHostRedirecton both hosts, with and without a query string/api/notices-adminand/api/v1/noticesare not host-neutral/api/v1/*and/api/auth/*still redirect to the app host, since neutralising those would break the session cookieWorth stating plainly: I could not reproduce the two-host behaviour end-to-end locally —
astro devrejects a spoofedHostheader with a 403 before middleware runs. The unit tests exercisegetCrossHostRedirectdirectly with real two-host URLs, and I confirmed it is the only cross-host redirect path inmiddleware.ts(the other isgetRetiredRedirect, which only maps/docsand/citation-dashboard). The end-to-end check belongs on the preview deploy or post-merge againstapp.nemar.org.