mirror of
https://github.com/different-ai/openwork
synced 2026-04-25 17:15:34 +02:00
push
This commit is contained in:
38
ee/apps/den-web/proxy.ts
Normal file
38
ee/apps/den-web/proxy.ts
Normal 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*"
|
||||
};
|
||||
Reference in New Issue
Block a user