Skip to content

Split nemar.org and app.nemar.org surfaces (#47) - #48

Merged
neuromechanist merged 2 commits into
mainfrom
feature/issue-47-app-subdomain-split
May 23, 2026
Merged

neuromechanist merged 2 commits into
mainfrom
feature/issue-47-app-subdomain-split

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #47.

Summary

  • src/middleware.ts reads Astro.url.hostname and 301-redirects mismatched paths between nemar.org and app.nemar.org. Anything else (localhost, *.pages.dev) runs in single-host mode so QA against one preview URL stays cheap.
  • Marketing host (nemar.org) skips the /auth/me round-trip entirely. The session cookie is intended to be host-only on app.nemar.org, so a stale wildcard cookie can never personalize a cacheable response here.
  • Nav renders host-aware: marketing has no UserMenu and a "Sign in" link to https://app.nemar.org/login; app collapses to UserMenu + "Explore datasets" cross-host link; dev/preview keeps the full nav.
  • Marketing pages that point at app routes (/upload on home, /login on /signup + /docs/getting-started, /dashboard on /docs/managing-datasets) now build absolute https://app.nemar.org/... URLs via appUrl(...) so they don't trigger an extra redirect hop.
  • src/lib/host.ts is the single place that knows the host map and the app-route list; src/components/Nav.astro, src/middleware.ts, and a few page files all import from it.

Test plan

  • bun run typecheck (0 errors)
  • bun run test (342/342 passing, +41 new tests)
  • bun run lint (clean)
  • Local dev: bun run dev and confirm /dashboard, /login, etc. all still render in single-host mode
  • Once app.nemar.org is attached on the Pages project, deploy and confirm /dashboard on nemar.org 301s to app.nemar.org/dashboard, and /discover on app.nemar.org 301s back to nemar.org/discover
  • Confirm the marketing host doesn't make any /auth/me calls (network panel on a nemar.org page)

Follow-ups (not in this PR)

  • Attach app.nemar.org as a second custom domain to the nemar-website Pages project (Cloudflare dashboard, Settings -> Custom domains).
  • Cross-check with nemarOrg/nemar-cli#569 that the backend Set-Cookie will use Domain=app.nemar.org (host-only) and CORS allows https://app.nemar.org. Full contract is captured on the local feature/auth-backend-pending branch's .context/handoff-auth-backend.md.

@neuromechanist neuromechanist linked an issue May 23, 2026 that may be closed by this pull request
8 tasks
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 23, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 294e370
Status: ✅  Deploy successful!
Preview URL: https://6005ec68.nemar-website.pages.dev
Branch Preview URL: https://feature-issue-47-app-subdoma.nemar-website.pages.dev

View logs

@neuromechanist

Copy link
Copy Markdown
Contributor Author

/review-pr outcomes

Four reviewers ran in parallel: code-reviewer, pr-test-analyzer, comment-analyzer, type-design-analyzer.

Addressed in 294e370

  • middleware: 307 for non-GET, no Cache-Control on the redirect. A 301 with a 5-minute cacheable header would (a) downgrade POST/PUT/DELETE to GET silently, (b) pin clients to the wrong host if we ever rebalance the route split. Now: GET/HEAD → 301, everything else → 307, no Cache-Control header.
  • middleware: JSDoc updated so it no longer claims "every authed request runs middleware" (marketing host now skips applySession).
  • host: hostMode() lowercases the hostname defensively (browsers normalize, proxies don't always; new test pins this).
  • host: marketingUrl JSDoc rephrased symmetrically with appUrl so the "relative when same-host or single-host" invariant is explicit.
  • Nav.astro: aria-current guarded against absolute hrefs with link.href.startsWith("/") — works today by accident, broken on the next absolute link added to the array.
  • Nav.astro: inline comment now mentions the marketing host falling into the same branch as single-host mode.
  • Tests added: /api/admin/users route classification, uppercase hostname normalization, 307 method preservation, no-Cache-Control assertion, marketing-host session-null path. 348/348 passing.

Skipped (with reasoning)

  • Un-export APP_HOST / MARKETING_HOST (type-design) — the constants are honest contract about which production hosts exist; tests legitimately use them to construct fixture URLs. Hiding them just forces tests to hardcode strings, which is worse for refactor safety.
  • Rename "single" → "passthrough" (type-design) — wording opinion. The current name is documented in JSDoc, matches "single-host mode" language used throughout AGENTS.md, the PR description, and other inline comments. Rename ripples too far for marginal clarity gain.
  • Pass HostMode into appUrl / marketingUrl (type-design) — the double hostMode() call is O(1) Set lookups. Most callers (signup.astro, getting-started.astro, managing-datasets.astro, index.astro) only have a hostname, not a precomputed HostMode. Forcing them to compute it first is friction without measurable benefit.
  • Hash-fragment redirect test (pr-test-analyzer) — URL#fragment never reaches the server in HTTP. A test would assert behavior the runtime can't actually exercise.

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.

Move authenticated routes to app.nemar.org

1 participant