BugFix: Proxy data, Logging with IP adresses
This commit is contained in:
@@ -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)}`);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user