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