This commit is contained in:
Benjamin Shafii
2026-03-27 07:39:12 -07:00
parent f2e5c4c9cb
commit 7fd45ff871
11 changed files with 468 additions and 58 deletions

38
ee/apps/den-web/proxy.ts Normal file
View File

@@ -0,0 +1,38 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const POSTHOG_PROXY_PATH = "/ow";
const POSTHOG_API_HOST = "us.i.posthog.com";
const POSTHOG_ASSETS_HOST = "us-assets.i.posthog.com";
export function proxy(request: NextRequest) {
const url = request.nextUrl.clone();
const { pathname } = url;
if (!pathname.startsWith(POSTHOG_PROXY_PATH)) {
return NextResponse.next();
}
const hostname = pathname.startsWith(`${POSTHOG_PROXY_PATH}/static/`)
? POSTHOG_ASSETS_HOST
: POSTHOG_API_HOST;
const requestHeaders = new Headers(request.headers);
requestHeaders.set("host", hostname);
requestHeaders.delete("cookie");
url.protocol = "https";
url.hostname = hostname;
url.port = "443";
url.pathname = pathname.replace(/^\/ow/, "") || "/";
return NextResponse.rewrite(url, {
request: {
headers: requestHeaders
}
});
}
export const config = {
matcher: "/ow/:path*"
};