BugFix: Proxy data, Logging with IP adresses

This commit is contained in:
2024-09-20 18:28:43 +02:00
parent 178f2b4810
commit 860d30b16f
11 changed files with 86 additions and 29 deletions

View File

@@ -3,16 +3,18 @@ import { ConfigService } from '@nestjs/config';
import { drizzle } from 'drizzle-orm/node-postgres';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import pkg from 'pg';
import { ContextService, RequestContext } from 'src/context/context.service';
import { Logger } from 'winston';
import * as schema from './schema';
import { PG_CONNECTION } from './schema';
const { Pool } = pkg;
@Module({
providers: [
ContextService,
{
provide: PG_CONNECTION,
inject: [ConfigService, WINSTON_MODULE_PROVIDER],
useFactory: async (configService: ConfigService, logger: Logger) => {
inject: [ConfigService, WINSTON_MODULE_PROVIDER, ContextService],
useFactory: async (configService: ConfigService, logger: Logger, contextService: ContextService) => {
const connectionString = configService.get<string>('DATABASE_URL');
const pool = new Pool({
connectionString,
@@ -21,7 +23,10 @@ const { Pool } = pkg;
// Definiere einen benutzerdefinierten Logger für Drizzle
const drizzleLogger = {
logQuery(query: string, params: unknown[]): void {
logger.info(query, params);
const context: RequestContext | undefined = contextService.getContext();
const ip = context?.ip || 'unknown';
const countryCode = context?.countryCode || 'unknown';
logger.info(`IP: ${ip} (${countryCode}) - Query: ${query} - Params: ${JSON.stringify(params)}`);
},
};