feat: Enhance audit logging with client IP tracking
- Integrated client IP address retrieval in the audit logging functionality across multiple controllers, including admin, common code, department, flow, screen, and table management. - Updated the `auditLogService` to include a new method for obtaining the client's IP address, ensuring accurate logging of user actions. - This enhancement improves traceability and accountability by capturing the source of requests, thereby strengthening the overall logging mechanism within the application.
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
import { Request } from "express";
|
||||
import { query, pool } from "../database/db";
|
||||
import logger from "../utils/logger";
|
||||
|
||||
export function getClientIp(req: Request): string {
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
if (forwarded) {
|
||||
const first = Array.isArray(forwarded) ? forwarded[0] : forwarded.split(",")[0];
|
||||
return first.trim();
|
||||
}
|
||||
const realIp = req.headers["x-real-ip"];
|
||||
if (realIp) {
|
||||
return Array.isArray(realIp) ? realIp[0] : realIp;
|
||||
}
|
||||
return req.ip || req.socket?.remoteAddress || "unknown";
|
||||
}
|
||||
|
||||
export type AuditAction =
|
||||
| "CREATE"
|
||||
| "UPDATE"
|
||||
|
||||
Reference in New Issue
Block a user