-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(posthog): replace proxy rewrite with route handler for reliable body streaming #3187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, no comments
|
@cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
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