Skip to content

Commit

Permalink
Add visitor ip if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevintjuhz committed Jan 30, 2025
1 parent cf6a538 commit b7d5693
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
5 changes: 5 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {

// src/index.ts
import { NextResponse } from "next/server";
import { ipAddress } from "@vercel/functions";
import { headers } from "next/headers";
function PreprMiddleware(request, response) {
var _a, _b, _c, _d;
Expand All @@ -14,6 +15,10 @@ function PreprMiddleware(request, response) {
const utm_content = request.nextUrl.searchParams.get("utm_content");
const utm_campaign = request.nextUrl.searchParams.get("utm_campaign");
const initial_referral = request.headers.get("referer");
const ip = ipAddress(request);
if (ip) {
newResponse.headers.set("Prepr-Visitor-IP", ip);
}
let cookie = (_a = request.cookies.get("__prepr_uid")) == null ? void 0 : _a.value;
const hutkCookie = (_b = request.cookies.get("hubspotutk")) == null ? void 0 : _b.value;
if (utm_source) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"dependencies": {
"@headlessui/react": "^2.1.8",
"@vercel/functions": "^1.6.0",
"classnames": "^2.5.1",
"clsx": "^2.1.1",
"micromatch": "^4.0.8",
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server'
import { ipAddress } from '@vercel/functions'
import { headers } from 'next/headers'

/**
Expand All @@ -16,6 +17,12 @@ export function PreprMiddleware(request: any, response?: NextResponse) {
const utm_campaign = request.nextUrl.searchParams.get('utm_campaign')
const initial_referral = request.headers.get('referer')

const ip = ipAddress(request)

if (ip) {
newResponse.headers.set('Prepr-Visitor-IP', ip)
}

let cookie = request.cookies.get('__prepr_uid')?.value
const hutkCookie = request.cookies.get('hubspotutk')?.value

Expand Down

0 comments on commit b7d5693

Please sign in to comment.