Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

781 B
Raw Blame
import { Request } from 'express';

/**
 * Pure request helper — no DB, no side effects — kept out of the injectable
 * AuditService so getClientIp-only consumers stay plain-function imports
 * (same carve-out precedent as files.constants.ts).
 *
 * It honours `trust proxy` (set in globalMiddleware from TRUST_PROXY, one hop by
 * default) rather than reading X-Forwarded-For itself. The leftmost entry of
 * that header is whatever the client typed, and this value ends up on the audit
 * rows an operator reads after an incident — the one place a caller must not be
 * able to dictate. With trust proxy off, req.ip is the socket address anyway.
 */
export function getClientIp(req: Request): string | null {
  return req.ip?.trim() || req.socket?.remoteAddress || null;
}