This commit is contained in:
Vallari-g 2025-02-20 01:04:09 -08:00
parent 9245fb5d80
commit 2ceeac20e0
2 changed files with 6 additions and 1 deletions

View file

@ -11,7 +11,7 @@ import {
} from 'next-basics'; } from 'next-basics';
import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants'; import { COLLECTION_TYPE, HOSTNAME_REGEX, IP_REGEX } from 'lib/constants';
import { secret, visitSalt, uuid } from 'lib/crypto'; import { secret, visitSalt, uuid } from 'lib/crypto';
import { hasBlockedIp } from 'lib/detect'; import { getIpAddress, hasBlockedIp } from 'lib/detect';
import { useCors, useSession, useValidate } from 'lib/middleware'; import { useCors, useSession, useValidate } from 'lib/middleware';
import { CollectionType, YupRequest } from 'lib/types'; import { CollectionType, YupRequest } from 'lib/types';
import { saveEvent, saveSessionData } from 'queries'; import { saveEvent, saveSessionData } from 'queries';
@ -137,6 +137,8 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
urlPath = urlPath.replace(/(.+)\/$/, '$1'); urlPath = urlPath.replace(/(.+)\/$/, '$1');
} }
const ip = req.body?.payload?.ip || getIpAddress(req);
await saveEvent({ await saveEvent({
urlPath, urlPath,
urlQuery, urlQuery,
@ -149,6 +151,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
...session, ...session,
sessionId: session.id, sessionId: session.id,
tag, tag,
ip,
}); });
} else if (type === COLLECTION_TYPE.identify) { } else if (type === COLLECTION_TYPE.identify) {
if (!data) { if (!data) {

View file

@ -40,6 +40,7 @@ export async function saveEvent(args: {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-Forwarded-For': args.ip,
}, },
body: JSON.stringify({ body: JSON.stringify({
fingerprint: args.sessionId, fingerprint: args.sessionId,
@ -53,6 +54,7 @@ export async function saveEvent(args: {
device: args.device, device: args.device,
screen: args.screen, screen: args.screen,
language: args.language, language: args.language,
ip: args.ip,
}), }),
}); });