mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-29 16:58:11 -05:00
fix(posthog): move session recording proxy to middleware for large payload support (#3065)
Next.js rewrites can strip request bodies for large payloads (1MB+), causing 400 errors from CloudFront. PostHog session recordings require up to 64MB per message. Moving the proxy to middleware ensures proper body passthrough. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -325,18 +325,6 @@ const nextConfig: NextConfig = {
|
||||
|
||||
return redirects
|
||||
},
|
||||
async rewrites() {
|
||||
return [
|
||||
{
|
||||
source: '/ingest/static/:path*',
|
||||
destination: 'https://us-assets.i.posthog.com/static/:path*',
|
||||
},
|
||||
{
|
||||
source: '/ingest/:path*',
|
||||
destination: 'https://us.i.posthog.com/:path*',
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
export default nextConfig
|
||||
|
||||
@@ -134,6 +134,24 @@ function handleSecurityFiltering(request: NextRequest): NextResponse | null {
|
||||
export async function proxy(request: NextRequest) {
|
||||
const url = request.nextUrl
|
||||
|
||||
if (url.pathname.startsWith('/ingest/')) {
|
||||
const hostname = url.pathname.startsWith('/ingest/static/')
|
||||
? 'us-assets.i.posthog.com'
|
||||
: 'us.i.posthog.com'
|
||||
|
||||
const targetPath = url.pathname.replace(/^\/ingest/, '')
|
||||
const targetUrl = `https://${hostname}${targetPath}${url.search}`
|
||||
|
||||
return NextResponse.rewrite(new URL(targetUrl), {
|
||||
request: {
|
||||
headers: new Headers({
|
||||
...Object.fromEntries(request.headers),
|
||||
host: hostname,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const sessionCookie = getSessionCookie(request)
|
||||
const hasActiveSession = isAuthDisabled || !!sessionCookie
|
||||
|
||||
@@ -195,6 +213,7 @@ export async function proxy(request: NextRequest) {
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
'/ingest/:path*', // PostHog proxy for session recording
|
||||
'/', // Root path for self-hosted redirect logic
|
||||
'/terms', // Whitelabel terms redirect
|
||||
'/privacy', // Whitelabel privacy redirect
|
||||
|
||||
Reference in New Issue
Block a user