diff --git a/apps/sdk-api/src/index.ts b/apps/sdk-api/src/index.ts index 54ad20f8..a84f4285 100644 --- a/apps/sdk-api/src/index.ts +++ b/apps/sdk-api/src/index.ts @@ -2,6 +2,7 @@ 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'; @@ -20,13 +21,24 @@ const port = parseInt(process.env.API_PORT || '3000', 10); const startServer = async () => { try { const fastify = Fastify({ - logger: pino({ level: 'info' }), + logger: pino({ + level: 'info', + }), }); fastify.register(cors, { 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' });