more testing with ip
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user