fix(posthog): replace proxy rewrite with route handler for reliable body streaming#3187
Merged
waleedlatif1 merged 2 commits intostagingfrom Feb 11, 2026
Merged
fix(posthog): replace proxy rewrite with route handler for reliable body streaming#3187waleedlatif1 merged 2 commits intostagingfrom
waleedlatif1 merged 2 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Greptile OverviewGreptile SummaryReplaced the PostHog proxy implementation from Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant NextMiddleware as Next.js Middleware (proxy.ts)
participant RouteHandler as Route Handler (/ingest/[[...path]])
participant PostHogAPI as PostHog API (us.i.posthog.com)
participant PostHogAssets as PostHog Assets (us-assets.i.posthog.com)
Note over Client,PostHogAssets: Before: Used NextResponse.rewrite() in middleware
Note over Client,PostHogAssets: After: Dedicated route handler with fetch()
Client->>NextMiddleware: POST /ingest/... (large payload)
Note over NextMiddleware: Excluded from matcher<br/>(prevents body buffering)
NextMiddleware->>RouteHandler: Pass through
alt Static asset request (/ingest/static/*)
RouteHandler->>PostHogAssets: fetch() with duplex: 'half'
PostHogAssets-->>RouteHandler: Asset response
else API request
RouteHandler->>PostHogAPI: fetch() with duplex: 'half'<br/>(streams body without buffering)
PostHogAPI-->>RouteHandler: API response
end
RouteHandler-->>Client: Streamed response
|
Collaborator
Author
|
@cursor review |
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.
Summary
NextResponse.rewrite()PostHog proxy with a dedicated route handler at/ingest/[[...path]]fetch()withduplex: 'half'for reliable request body streaming (fixes ECONNRESET errors on large payloads like session recordings)/ingestfrom proxy matcher to prevent Next.js 16 body buffering interferenceType of Change
Testing
Tested manually
Checklist