Skip to content

fix(web): exclude PostHog proxy from i18n middleware - #1626

Merged
lawrencecchen merged 3 commits into
mainfrom
fix-posthog-middleware
Mar 18, 2026
Merged

lawrencecchen merged 3 commits into
mainfrom
fix-posthog-middleware

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The i18n middleware added in cf75da8f intercepts /cmuxterm/* requests (PostHog reverse proxy), breaking all analytics since March 12.
  • Add cmuxterm to the middleware matcher's negative lookahead so PostHog proxy requests bypass i18n routing.

Testing

  • Verify pageviews resume on PostHog dashboard after deploy.
  • Confirm i18n locale detection still works for all other routes.

Related


Summary by cubic

Switch PostHog to the managed reverse proxy at https://r.cmux.dev and remove the /cmuxterm rewrites, eliminating the i18n matcher conflict and restoring analytics. Rename the middleware to web/proxy.ts for Next.js 16; locale detection for other routes is unchanged.

Written for commit 4e6a0b8. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Broadened route-matching exclusions to omit additional paths from standard processing, refining request handling.
  • Bug Fixes / Maintenance
    • Removed legacy proxy rewrite rules that routed certain paths through external rewrite mappings.
  • Telemetry
    • Switched analytics initialization to use an absolute analytics endpoint URL to ensure consistent event delivery.

The next-intl middleware added in cf75da8 intercepts /cmuxterm/* requests
(the PostHog reverse proxy), causing analytics to break since March 12.
Add cmuxterm to the negative lookahead so proxy requests bypass i18n.
@vercel

vercel Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Mar 17, 2026 11:43pm

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitai Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 46e5df7a-ffee-4f11-bfa9-988ab7d2f914

📥 Commits

Reviewing files that changed from the base of the PR and between aa00c5d and 4e6a0b8.

📒 Files selected for processing (3)
  • web/app/[locale]/posthog.tsx
  • web/next.config.ts
  • web/proxy.ts
💤 Files with no reviewable changes (1)
  • web/next.config.ts

📝 Walkthrough

Walkthrough

Updated middleware matcher to exclude cmuxterm; switched PostHog api_host from a relative path to https://r.cmux.dev; removed Next.js rewrites that proxied /cmuxterm/* and /cmuxterm/static/*.

Changes

Cohort / File(s) Summary
Middleware Route Configuration
web/proxy.ts
Changed config.matcher negative lookahead to also exclude cmuxterm (`"/((?!api
Analytics Config
web/app/[locale]/posthog.tsx
PostHog initialization: api_host changed from "/cmuxterm" to absolute URL https://r.cmux.dev; other PostHog options unchanged.
Next.js Rewrites Removed
web/next.config.ts
Removed async rewrites() containing two rewrite rules that proxied /cmuxterm/static/:path* and /cmuxterm/:path* to external PostHog hosts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through lines of route and host,
I nudged cmuxterm off the middleware post,
Swapped a path for a shiny domain,
Rewrites gone — the mapping changed its frame,
A tiny hop, a tidy code-toast 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: excluding PostHog proxy from i18n middleware. It directly addresses the core issue and is clear, specific, and concise.
Description check ✅ Passed The description includes a clear summary of the problem and solution, testing instructions, and related context. However, the Testing section lacks detail about how the changes were verified locally, and the Review Trigger, Checklist sections are not completed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-posthog-middleware
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

Next.js 16 renamed middleware.ts to proxy.ts. Migrate to the new
convention since we're on Next.js 16.1.6.
Replace the Next.js rewrites-based proxy (/cmuxterm -> us.i.posthog.com)
with PostHog's managed reverse proxy at r.cmux.dev. This removes the
rewrites from next.config.ts entirely and eliminates the proxy.ts
matcher conflict that caused the analytics regression.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="web/proxy.ts">

<violation number="1">
P1: `cmuxterm` was removed from the exclusion matcher, so `/cmuxterm/*` is routed through i18n middleware again and the PostHog proxy path will be intercepted.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@lawrencecchen
lawrencecchen merged commit 93d2245 into main Mar 18, 2026
14 checks passed
@lawrencecchen
lawrencecchen deleted the fix-posthog-middleware branch March 18, 2026 00:02
bn-l pushed a commit to bn-l/cmux that referenced this pull request Apr 3, 2026
* fix(web): exclude PostHog proxy path from i18n middleware

The next-intl middleware added in 1476b2e intercepts /cmuxterm/* requests
(the PostHog reverse proxy), causing analytics to break since March 12.
Add cmuxterm to the negative lookahead so proxy requests bypass i18n.

* refactor(web): rename middleware.ts to proxy.ts for Next.js 16

Next.js 16 renamed middleware.ts to proxy.ts. Migrate to the new
convention since we're on Next.js 16.1.6.

* feat(web): migrate PostHog to managed reverse proxy at r.cmux.dev

Replace the Next.js rewrites-based proxy (/cmuxterm -> us.i.posthog.com)
with PostHog's managed reverse proxy at r.cmux.dev. This removes the
rewrites from next.config.ts entirely and eliminates the proxy.ts
matcher conflict that caused the analytics regression.

---------

Co-authored-by: Lawrence Chen <lawrencecchen@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview — 4e6a0b81 Deployed Mar 17, 2026 by vercel[bot]
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.

1 participant