Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

sdk api add debug logging

Carl-Gerhard Lindesvärd500518b6e806
diff --git a/apps/sdk-api/src/index.ts b/apps/sdk-api/src/index.ts
index 54ad20f86..a84f42853 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' });