From 63531f8753243cc1f717487762b0e329e086869a Mon Sep 17 00:00:00 2001 From: Sergei Meza Date: Tue, 18 Oct 2022 16:37:05 +0900 Subject: [PATCH] add cookie. add city database --- lib/request.js | 4 ++-- lib/session.js | 7 +++++-- pages/api/collect.js | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/request.js b/lib/request.js index 1ad0c130..865d701f 100644 --- a/lib/request.js +++ b/lib/request.js @@ -80,9 +80,9 @@ export async function getCountry(req, ip) { return result?.country?.iso_code; } -export async function getClientInfo(req, { screen, ip }) { +export async function getClientInfo(req, { screen }) { const userAgent = req.headers['user-agent']; - // const ip = getIpAddress(req); + const ip = getIpAddress(req); const country = await getCountry(req, ip); const browser = browserName(userAgent); const os = detectOS(userAgent); diff --git a/lib/session.js b/lib/session.js index 81964676..913b0927 100644 --- a/lib/session.js +++ b/lib/session.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { parseToken } from 'next-basics'; import { validate } from 'uuid'; import { uuid } from 'lib/crypto'; @@ -45,8 +46,10 @@ export async function getSession(req) { throw new Error(`Website not found: ${website_uuid}`); } - const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; - const { userAgent, browser, os, country, device } = await getClientInfo(req, payload); + // const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; + const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload); + + console.log('ip:', ip); let session_uuid = uuid(websiteId, hostname, ip, userAgent); if (process.env.CROSSDOMAIN_TRACKING) { diff --git a/pages/api/collect.js b/pages/api/collect.js index 7fd7ffdf..dd1333bf 100644 --- a/pages/api/collect.js +++ b/pages/api/collect.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const { Resolver } = require('dns').promises; import isbot from 'isbot'; import ipaddr from 'ipaddr.js'; @@ -38,6 +39,7 @@ export default async (req, res) => { const clientIp = getIpAddress(req); const blocked = ips.find(ip => { + console.log('collect.js', ip, clientIp); if (ip === clientIp) return true; // CIDR notation