more testing with ip
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
"fastify-sse-v2": "^3.1.2",
|
||||
"pino": "^8.17.2",
|
||||
"ramda": "^0.29.1",
|
||||
"request-ip": "^3.3.0",
|
||||
"ua-parser-js": "^1.0.37"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -28,7 +27,6 @@
|
||||
"@mixan/tsconfig": "workspace:*",
|
||||
"@mixan/types": "workspace:*",
|
||||
"@types/ramda": "^0.29.6",
|
||||
"@types/request-ip": "^0.0.41",
|
||||
"@types/ua-parser-js": "^0.7.39",
|
||||
"eslint": "^8.48.0",
|
||||
"prettier": "^3.0.3",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { parseIp } from '@/utils/parseIp';
|
||||
import { getClientIp, parseIp } from '@/utils/parseIp';
|
||||
import { getReferrerWithQuery, parseReferrer } from '@/utils/parseReferrer';
|
||||
import { parseUserAgent } from '@/utils/parseUserAgent';
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import { omit } from 'ramda';
|
||||
import { getClientIp } from 'request-ip';
|
||||
|
||||
import { generateProfileId, getTime, toISOString } from '@mixan/common';
|
||||
import type { IServiceCreateEventPayload } from '@mixan/db';
|
||||
@@ -86,6 +85,8 @@ export async function postEvent(
|
||||
eventsQueue.getJobs(['delayed']),
|
||||
]);
|
||||
|
||||
console.log('----->', projectId, ip, geo);
|
||||
|
||||
// find session_end job
|
||||
const sessionEndJobCurrentProfileId = findJobByPrefix(
|
||||
eventsJobs,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { parseIp } from '@/utils/parseIp';
|
||||
import { getClientIp, parseIp } from '@/utils/parseIp';
|
||||
import { parseUserAgent } from '@/utils/parseUserAgent';
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import { assocPath, mergeDeepRight, path } from 'ramda';
|
||||
import { getClientIp } from 'request-ip';
|
||||
|
||||
import { generateProfileId, toDots } from '@mixan/common';
|
||||
import type { IDBProfile, Profile } from '@mixan/db';
|
||||
import type { IDBProfile } from '@mixan/db';
|
||||
import { db, getSalts } from '@mixan/db';
|
||||
import type {
|
||||
IncrementProfilePayload,
|
||||
|
||||
@@ -2,7 +2,6 @@ import cors from '@fastify/cors';
|
||||
import Fastify from 'fastify';
|
||||
import { FastifySSEPlugin } from 'fastify-sse-v2';
|
||||
import pino from 'pino';
|
||||
import { getClientIp } from 'request-ip';
|
||||
|
||||
import { redisPub } from '@mixan/redis';
|
||||
|
||||
@@ -30,15 +29,6 @@ const startServer = async () => {
|
||||
origin: '*',
|
||||
});
|
||||
|
||||
fastify.addHook('preHandler', (req, reply, done) => {
|
||||
const ip = getClientIp(req)!;
|
||||
console.log('---------------');
|
||||
console.log('ip', ip);
|
||||
console.log('heacders', req.headers);
|
||||
console.log('---------------');
|
||||
done();
|
||||
});
|
||||
|
||||
fastify.register(FastifySSEPlugin);
|
||||
fastify.decorateRequest('projectId', '');
|
||||
fastify.register(eventRouter, { prefix: '/event' });
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { FastifyRequest, RawRequestDefaultExpression } from 'fastify';
|
||||
|
||||
interface RemoteIpLookupResponse {
|
||||
country: string | undefined;
|
||||
city: string | undefined;
|
||||
@@ -21,6 +23,18 @@ const geo: GeoLocation = {
|
||||
|
||||
const ignore = ['127.0.0.1', '::1'];
|
||||
|
||||
export function getClientIp(req: FastifyRequest) {
|
||||
if (req.headers['cf-connecting-ip']) {
|
||||
return String(req.headers['cf-connecting-ip']);
|
||||
}
|
||||
|
||||
if (req.headers['x-forwarded-for']) {
|
||||
return String(req.headers['x-forwarded-for']);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function parseIp(ip?: string): Promise<GeoLocation> {
|
||||
if (!ip || ignore.includes(ip)) {
|
||||
return geo;
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -216,9 +216,6 @@ importers:
|
||||
ramda:
|
||||
specifier: ^0.29.1
|
||||
version: 0.29.1
|
||||
request-ip:
|
||||
specifier: ^3.3.0
|
||||
version: 3.3.0
|
||||
ua-parser-js:
|
||||
specifier: ^1.0.37
|
||||
version: 1.0.37
|
||||
@@ -238,9 +235,6 @@ importers:
|
||||
'@types/ramda':
|
||||
specifier: ^0.29.6
|
||||
version: 0.29.7
|
||||
'@types/request-ip':
|
||||
specifier: ^0.0.41
|
||||
version: 0.0.41
|
||||
'@types/ua-parser-js':
|
||||
specifier: ^0.7.39
|
||||
version: 0.7.39
|
||||
|
||||
Reference in New Issue
Block a user