Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .planning/architecture/helldivers-bot-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ not hold yet backfills it through the update pipeline's `updateSeason()`.
| `src/app/api/auth/[...all]/route.js` | — | BetterAuth catch-all (503 when auth is disabled) |
| `src/app/api/healthcheck/route.js` | none | Liveness for the swarm health check |
| `src/app/api/glitchtip/route.js`, `src/app/api/umami/route.js` | none | Sentry tunnel and Umami proxy, so ad blockers don't break them |
| `src/app/stats.js/route.js`, `src/app/recorder.js/route.js` | none | Umami script proxies (`proxyUmamiScript`) |
| `src/app/stats.js/route.js` | none | Umami script proxy (`proxyUmamiScript`) |

## Rules it keeps

Expand Down
2 changes: 1 addition & 1 deletion .planning/codebase/INTEGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

**Analytics:**
- Umami v3 (self-hosted, cookieless) — `UMAMI_SITE_URL`, `UMAMI_SITE_ID`
- Client scripts served same-origin by route handlers: `/stats.js` and `/recorder.js` fetch `script.js` / `recorder.js` from `UMAMI_SITE_URL` with no visitor headers (`proxyUmamiScript` in `src/shared/utils/umami.mjs`); event posts proxied via `/api/send` → `/api/umami`; recorder data via rewrites `/api/record` and `/api/websites/:id/recorder` (all to dodge ad blockers)
- Client script served same-origin by a route handler: `/stats.js` fetches `script.js` from `UMAMI_SITE_URL` with no visitor headers (`proxyUmamiScript` in `src/shared/utils/umami.mjs`); event posts proxied via `/api/send` → `/api/umami` (both to dodge ad blockers). No session recorder: replay needs consent (#617)
- Server-side event sender: `sendUmamiEvent()` in `src/shared/utils/umami.mjs` — posts directly server-to-server, production-only (`NODE_ENV === 'production'` gate), used inside `after()` calls in API routes so it never blocks the response
- Client-side dynamic tracking: `useTrack()` hook (`src/shared/hooks/useTrack.mjs`) and direct `window.umami?.track()` calls
- Declarative tracking: `data-umami-event="category-action"` HTML attributes, auto-captured by the tracker script
Expand Down
2 changes: 1 addition & 1 deletion .planning/codebase/STACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
- Build-time vs runtime vars distinguished: `NEXT_PUBLIC_*` vars are inlined at `next build` time (site URL, deploy env, VAPID public key, Sentry DSN, app version)

**Build:**
- `next.config.mjs` — MDX wrapper, conditional Sentry wrapper (only when `SENTRY_AUTH_TOKEN` set), security headers, cache-control rules per route type, redirects (`/war` → `/archives`, `/profile/admin` → `/profile`), rewrites (`/api/send` → `/api/umami`, `/api/record` and `/api/websites/:id/recorder` → Umami recorder endpoints); `/stats.js` and `/recorder.js` are route handlers, not rewrites
- `next.config.mjs` — MDX wrapper, conditional Sentry wrapper (only when `SENTRY_AUTH_TOKEN` set), security headers, cache-control rules per route type, redirects (`/war` → `/archives`, `/profile/admin` → `/profile`), rewrites (`/api/send` → `/api/umami`); `/stats.js` is a route handler, not a rewrite
- `deploymentId` set from `package.json` version (dots replaced with dashes) — drives Next.js's built-in stale-chunk detection
- `jsconfig.json` — `@/*` → `./src/*` path alias, `@test-utils` alias, `checkJs: true` strict-null JSDoc typechecking with `noImplicitAny: false`
- `browserslist` in `package.json`: `defaults`, Firefox ≥115, Chrome ≥109, Safari ≥15.6, excludes dead/op_mini/kaios/android-browser
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

### Fixed

- Session replay is off for every visitor (#617). No page loads the Umami recorder (replay and
heatmaps), because it needs consent and the site has no consent UI yet. The `/recorder.js` route
and the `/api/record` and `/api/websites/:id/recorder` rewrites are gone, so a tab that loaded the
recorder before the deploy cannot upload either. Cookieless Umami page counting stays. `/legal`
says replay is off.
- docs: correct stale README/CONTRIBUTING/AGENTS lines.
- The `/docs` pages now match the code on the points the phase verification found. A new service
worker activates at once. The `h1_*` panels on `/docs/architecture` use the schema types. The
Expand Down
19 changes: 2 additions & 17 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,6 @@ const nextConfig = {
source: '/api/send',
destination: '/api/umami',
},
// Session replay + heatmaps. /stats.js and /recorder.js are route
// handlers (src/app/stats.js/, src/app/recorder.js/), because a
// rewrite forwards the visitor's cookies to the Umami host. The
// rewrites below carry no cookie: recorder.js calls them with
// credentials: "omit". The host is fixed here, not read from
// UMAMI_SITE_URL: rewrites are resolved at build time and that
// variable exists only at runtime.
{
source: '/api/record',
destination: 'https://umami.lav.ren/api/record',
},
{
source: '/api/websites/:id/recorder',
destination: 'https://umami.lav.ren/api/websites/:id/recorder',
},
];
},
async headers() {
Expand Down Expand Up @@ -181,7 +166,7 @@ const nextConfig = {
// /_next/* — Next.js asset/data chunks (content-hashed)
// asset roots — pinned `immutable` above with longer TTLs
// /sw.js — service worker must always revalidate
// /stats.js, /recorder.js — the Umami script handlers set their own
// /stats.js — the Umami script handler sets its own
// Cache-Control
// /workers/* — cron worker source (immutable above)
// /profile/* — per-user content, must not be shared
Expand All @@ -191,7 +176,7 @@ const nextConfig = {
// config-level header previously overrode both,
// silently freezing a cached fallback in front
// of every crawler until the segment TTL expired
source: '/((?!api/|_next/|profile|favicons/|fonts/|icons/|images/|svgs/|sw\\.js|stats\\.js|recorder\\.js|workers/|opengraph-image).*)',
source: '/((?!api/|_next/|profile|favicons/|fonts/|icons/|images/|svgs/|sw\\.js|stats\\.js|workers/|opengraph-image).*)',
headers: [
{
key: 'Cache-Control',
Expand Down
10 changes: 5 additions & 5 deletions src/app/docs/infrastructure/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,11 @@ The service worker at `src/sw.js` runs in a separate worker context with no DOM,

Umami v3 analytics use a same-origin proxy to bypass ad blockers:

1. **Script proxy:** `/stats.js` and `/recorder.js` are route handlers (`src/app/stats.js/route.js`, `src/app/recorder.js/route.js`, shared code `proxyUmamiScript` in `src/shared/utils/umami.mjs`). Each fetches `script.js` or `recorder.js` from `UMAMI_SITE_URL` with no visitor headers, so visitor cookies, the auth session cookie included, never reach the Umami host. A Next.js rewrite would forward them.
1. **Script proxy:** `/stats.js` is a route handler (`src/app/stats.js/route.js`, shared code `proxyUmamiScript` in `src/shared/utils/umami.mjs`). It fetches `script.js` from `UMAMI_SITE_URL` with no visitor headers, so visitor cookies, the auth session cookie included, never reach the Umami host. A Next.js rewrite would forward them.
2. **Data proxy:** `/api/send` → `/api/umami` (Next.js rewrite) → `https://<UMAMI_SITE_URL>/api/send` (API route proxy)
3. **Recorder data:** `/api/record` and `/api/websites/:id/recorder` are Next.js rewrites to the Umami host, fixed in `next.config.mjs` and not read from `UMAMI_SITE_URL`: rewrites are resolved at build time, and that variable exists only at runtime. The recorder calls them with `credentials: "omit"`, so the browser attaches no cookie. `RecorderScript` renders the recorder only for browsers without the `umami.disabled` opt-out flag. Replays and heatmaps stay inert until they are turned on for the site in Umami.
3. **No session replay:** the site serves and relays no Umami recorder (session replay and heatmaps). Replay needs consent, and the site has no consent UI yet (#617).

The proxy writes the visitor's IP from Cloudflare's `cf-connecting-ip` into the hit as `payload.ip`, so Umami uses the visitor, not this server, for its cookieless session hash and its location. Without it, the relay's second pass through Cloudflare labels every hit with the server's IP and country. The app sets no Content-Security-Policy header and the production edge sets one. Every Umami request (script, send, recorder) is same-origin, so `'self'` in `script-src` and `connect-src` covers it and no Umami domain needs an allowance.
The proxy writes the visitor's IP from Cloudflare's `cf-connecting-ip` into the hit as `payload.ip`, so Umami uses the visitor, not this server, for its cookieless session hash and its location. Without it, the relay's second pass through Cloudflare labels every hit with the server's IP and country. The app sets no Content-Security-Policy header and the production edge sets one. Every Umami request (script, send) is same-origin, so `'self'` in `script-src` and `connect-src` covers it and no Umami domain needs an allowance.

Env vars: `UMAMI_SITE_URL` (domain without protocol, e.g., `umami.example.com`), `UMAMI_SITE_ID` (website UUID).

Expand Down Expand Up @@ -541,7 +541,7 @@ Every key below is in `.example.env`. That file is the source for the descriptio
| `BUCKET_SIZE` | No | Updates | Bucket size in seconds for the `h1_status`, `h1_statistic` and `h1_event_progress` upserts; default `900` (15 min). A smaller value gives finer archives and more storage. Changing it mixes granularities in the history |
| `NEXT_PUBLIC_SITE_URL` | No | Site | Public site origin (e.g. `https://helldivers.bot`); inlined at build time so self-hosters can serve under their own domain. Defaults to `https://helldivers.bot` (`src/config/site.mjs`). |
| `UMAMI_SITE_ID` | No | Analytics | Umami website tracking ID; if absent, the Umami script is not loaded. Server-side events go out in production only |
| `UMAMI_SITE_URL` | No | Analytics | Umami instance domain, without protocol or port; used in server-side fetch calls. If absent, `/stats.js` and `/recorder.js` answer 404 |
| `UMAMI_SITE_URL` | No | Analytics | Umami instance domain, without protocol or port; used in server-side fetch calls. If absent, `/stats.js` answers 404 |
| `SENTRY_DSN` | No | Error tracking | Sentry DSN for server-side error reporting (points to GlitchTip); if absent, error tracking disabled |
| `NEXT_PUBLIC_SENTRY_DSN` | No | Error tracking | Sentry DSN for client-side error reporting (same DSN, exposed to browser); a build argument, inlined at build time |
| `SENTRY_AUTH_TOKEN` | No | Error tracking | GlitchTip API token for source map uploads; if absent, `withSentryConfig` build plugin skipped |
Expand Down Expand Up @@ -632,7 +632,7 @@ npx pwa-asset-generator public/images/logo_square.png public/splash \
| `/svgs/*` | `public, max-age=31536000, immutable` (1 year) |
| `/workers/*` | `public, max-age=86400, immutable` (1 day) |
| `/sw.js` | `no-cache, no-store, must-revalidate` |
| HTML page routes (not the paths above, `/api/*`, `/_next/*`, `/profile*`, `/stats.js`, `/recorder.js` or `/opengraph-image`) | `public, s-maxage=30, stale-while-revalidate=60` |
| HTML page routes (not the paths above, `/api/*`, `/_next/*`, `/profile*`, `/stats.js` or `/opengraph-image`) | `public, s-maxage=30, stale-while-revalidate=60` |

The service worker is built from `src/sw.js` into `public/sw.js` by `serwist build`, which `npm run build` runs after `next build`. The built file is git-ignored. It is never HTTP-cached, so a browser detects a new version on every navigation. `skipWaiting` and `clientsClaim` in `src/sw.js` then activate it. The `s-maxage` header on page routes lets Cloudflare collapse concurrent visitors into one origin request per 30 seconds. Browsers still revalidate normally.

Expand Down
29 changes: 10 additions & 19 deletions src/app/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Header from '@/shared/components/Header/Header';
import Footer from '@/shared/components/Footer/Footer';
import BottomNav from '@/shared/components/BottomNav/BottomNav';
import PreferenceTracker from '@/shared/components/PreferenceTracker';
import RecorderScript from '@/shared/components/RecorderScript';
import ServiceWorkerRegister from '@/shared/components/ServiceWorkerRegister';
import LiveDataProvider from '@/shared/providers/LiveDataProvider';
import MinistryProvider from '@/features/ministry/MinistryProvider';
Expand Down Expand Up @@ -249,25 +248,17 @@ export default async function RootLayout({ children }) {
</MinistryProvider>
</LiveDataProvider>
<ServiceWorkerRegister />
{/* No session replay: the recorder needs consent (analytics
standard, Tier 2), and there is no consent UI yet (#617). */}
{isProduction && process.env.UMAMI_SITE_ID ?
<>
<Script
nonce={nonce}
// src="https://umami.lav.ren/script.js"
src="/stats.js"
data-website-id={process.env.UMAMI_SITE_ID}
data-performance="true"
strategy="afterInteractive"
/>
{/* Session replay + heatmaps, served same-origin by
src/app/recorder.js/route.js. Rendered only for
browsers that have not opted out; inert until
turned on for this site in Umami. */}
<RecorderScript
nonce={nonce}
siteId={process.env.UMAMI_SITE_ID}
/>
</>
<Script
nonce={nonce}
// src="https://umami.lav.ren/script.js"
src="/stats.js"
data-website-id={process.env.UMAMI_SITE_ID}
data-performance="true"
strategy="afterInteractive"
/>
: null}
</body>
</html>
Expand Down
19 changes: 5 additions & 14 deletions src/app/legal/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function LegalPage() {
Approved for citizen consumption by Super Earth High Command
</p>
<p className="mt-1 text-small text-text-muted italic">
Last updated: April 2026
Last updated: December 2026
</p>
</header>

Expand Down Expand Up @@ -191,19 +191,10 @@ export default function LegalPage() {
Session Recording Protocols
</h3>
<p>
A sample of visits may be recorded for review. A recording is not
video and not a capture of your screen — the page structure and
its text are re-serialised and replayed, which is how the Ministry
identifies where the interface fails its citizens. Anything you
type into a form field is masked inside your own browser before
transmission, so the value itself never leaves your device. Click
and scroll heatmaps are collected separately from recordings:
pointer positions and scroll depth per page, sampled on their own,
so a visit can add to a heatmap without being recorded. A browser
that has opted out (see Citizen Rights) does not load the
recorder. Note that while you are signed in, a recording is linked
to your citizen ID by the section above, and is therefore
attributable to your account rather than anonymous.
Session replay is off. The terminal does not load the session
recorder for any citizen, so it creates no session recordings and
collects no click or scroll heatmaps. Recordings made before
replay was switched off fall under Data Retention Protocols below.
</p>

<h3 className="text-h3 font-bold text-text uppercase">
Expand Down
11 changes: 0 additions & 11 deletions src/app/recorder.js/route.js

This file was deleted.

Loading
Loading