Skip to content

Commit

Permalink
Test proxying mixpanel requests
Browse files Browse the repository at this point in the history
  • Loading branch information
hbenl committed Jun 27, 2024
1 parent 3bd10eb commit 437a7d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ export async function middleware(request: NextRequest) {
const { nextUrl } = request;
const { pathname } = nextUrl;

if (["/track", "/engage"].includes(pathname)) {
const headers = new Headers();
headers.set("cookie", "");
headers.set("foo", "bar");
headers.set("x-foo", "bar");
// const ip = request.headers.get("x-forwarded-for");
// if (ip) {
// console.log(`IP: ${ip}`);
// // headers.set("X-Real-IP", ip);
// // headers.set("X-Forwarded-For", ip);
// }
// // headers.set("x-middleware-rewrite", )
// headers.set("foo", "bar");
// headers.set("x-foo", "bar");
return NextResponse.rewrite("https://holger.evandor.de/track/", { headers });
// return new NextResponse(null, { headers });
}

const response = NextResponse.next();

const { ua } = userAgent(request);
Expand Down
1 change: 1 addition & 0 deletions src/utils/mixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const initializeMixPanel = () => {
mixpanel.init("ffaeda9ef8fb976a520ca3a65bba5014", {
track_pageview: true,
persistence: "localStorage",
api_host: location.origin,
});
};

0 comments on commit 437a7d8

Please sign in to comment.