Skip to main content

@rtorcato/api-express-utils v1.0.0

Interfaces

RouteInfo

Defined in: logRoutes.ts:3

Properties

method

method: string

Defined in: logRoutes.ts:4

path

path: string

Defined in: logRoutes.ts:5

Functions

getIP()

getIP(req): string | undefined

Defined in: getIP.ts:15

Extract the client IP from an Express request.

Order: X-Forwarded-For (leftmost entry) → req.ipsocket.remoteAddress.

SECURITY: X-Forwarded-For is client-supplied and trivially spoofable unless the request passed through a proxy you control that overwrites it. If you are behind a trusted proxy, prefer configuring app.set('trust proxy', …) and reading req.ip directly — Express then validates the hop chain for you. Only rely on this helper's XFF parsing for logging/analytics, never for authorization or rate-limit keys on untrusted ingress.

Parameters

req

Request

Returns

string | undefined


logRoutes()

logRoutes(app, opts?): RouteInfo[]

Defined in: logRoutes.ts:32

Walk an Express app's router stack and return its registered routes.

Also prints them (one METHOD /path per line) via log unless log: false. Works on Express 4 (app._router) and Express 5 (app.router).

Parameters

app

Express

opts?
log?

boolean | ((line) => void)

Returns

RouteInfo[]