Skip to content

fix(umami): restore /stats rewrite dropped during env-agnostic refactor - #106

Merged
danielheene merged 3 commits into
mainfrom
fix/umami-stats-rewrite
Oct 9, 2026
Merged

danielheene merged 3 commits into
mainfrom
fix/umami-stats-rewrite

Conversation

@danielheene

Copy link
Copy Markdown
Owner

Summary

  • Restores the rewrites() function in next.config.ts that proxies /stats/:match* → ${NEXT_PUBLIC_UMAMI_URL}/:match*
  • The rewrite was dropped during the env-agnostic compile refactor (fcfa5cb) which removed the async rewrites() block
  • Without it, browser-side /stats/api/send requests hit a missing route, Next.js tries to proxy to localhost:3002 (from .env.test), fails with ECONNREFUSED, and floods the server log
  • Added a runtime guard (if (!umamiUrl) return []) and a comment explaining why process.env['NEXT_PUBLIC_UMAMI_URL'] is safe here (read dynamically at server startup, not inlined at build time, so won't trigger check-env-leak)

Test plan

  • Verify bun run lint passes
  • Verify E2E no longer shows ECONNREFUSED spam in server logs for /stats requests

The async rewrites() block was removed when the compile was made
environment-agnostic, but it reads process.env dynamically at server
startup (not build time) so it never leaks into the bundle. Without it
browser-side /stats/api/send requests hit a missing route, Next.js
tries to proxy them to localhost:3002, and ECONNREFUSED errors flood
the server log in CI and any environment where Umami is unreachable.

Restored with a runtime guard (no-op when NEXT_PUBLIC_UMAMI_URL is unset)
and a comment explaining why the dynamic read is safe here.
@kilo-code-bot

kilo-code-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
app/(frontend)/stats/[...path]/route.ts 22 Silent 204 response hides missing Umami configuration

SUGGESTION

File Line Issue
app/(frontend)/stats/[...path]/route.ts 41 Filter sensitive headers from upstream response
Files Reviewed (1 file)
  • app/(frontend)/stats/[...path]/route.ts - 2 issues

Fix these issues in Kilo Cloud

Previous Review Summaries (2 snapshots, latest commit 5d954e1)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 5d954e1)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
app/(frontend)/stats/[...path]/route.ts 19 Silent 204 response hides missing Umami configuration

SUGGESTION

File Line Issue
app/(frontend)/stats/[...path]/route.ts 38 Filter sensitive headers from upstream response
Files Reviewed (3 files)
  • app/(frontend)/stats/[...path]/route.ts - 2 issues
  • next.config.ts - No issues
  • src/lib/umami/sendUmamiPayload.ts - No issues

Fix these issues in Kilo Cloud

Previous review (commit d2fec48)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • next.config.ts - Restores Umami stats rewrite proxy

Reviewed by free · Input: 213.7K · Output: 19.6K · Cached: 179.7K

…v-leak

next.config.ts rewrites() embeds the destination URL into routes-manifest.json
at build time, which causes check-env-leak to flag NEXT_PUBLIC_UMAMI_URL in the
compiled output. Replace the rewrite with a /stats/[...path] route handler that
reads the Umami URL at request time instead.
): Promise<NextResponse> {
const umamiUrl = process.env['NEXT_PUBLIC_UMAMI_URL']
if (!umamiUrl) {
return new NextResponse(null, { status: 204 })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Silent 204 response hides missing Umami configuration

When NEXT_PUBLIC_UMAMI_URL is not set, the route returns 204 (No Content) instead of 404 or 500. This makes the client think the analytics request succeeded when it was actually dropped. The previous rewrite approach simply didn't create the route (returning []), so clients would get a 404. Consider returning 503 or 404 to surface configuration issues, or at minimum log a warning server-side.


return new NextResponse(upstream.body, {
status: upstream.status,
headers: upstream.headers,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Filter sensitive headers from upstream response

Passing all upstream headers (upstream.headers) back to the client could leak headers like set-cookie, content-encoding, transfer-encoding, etc. For an analytics proxy, consider filtering to only safe headers (e.g., content-type, cache-control) or explicitly removing sensitive ones.

…ler inlining

process.env['NEXT_PUBLIC_UMAMI_URL'] in a server route file is still inlined by
the Next.js bundler into server chunks, triggering check-env-leak. Switch to
readRuntimeConfigFromEnv().umamiUrl which uses the bracket-notation readEnv()
helper that the bundler does not statically inline.
@danielheene
danielheene merged commit 8b412c1 into main Oct 9, 2026
7 checks passed
@danielheene
danielheene deleted the fix/umami-stats-rewrite branch October 9, 2026 09:44
danielheene-website-release Bot pushed a commit that referenced this pull request Oct 9, 2026
## [1.12.2](v1.12.1...v1.12.2) (2026-10-09)

### Bug Fixes

* **umami:** restore /stats rewrite dropped during env-agnostic refactor ([#106](#106)) ([8b412c1](8b412c1))
@danielheene-website-release

Copy link
Copy Markdown

🎉 This PR is included in version 1.12.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

This branch was successfully deployed

1 active deployment
Testing — 757f8cc7 Deployed Oct 9, 2026 by danielheene via CI / E2E Tests #78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant