| 1 | import type { Request } from 'express'; |
| 2 | |
| 3 | /** The address a request came from: Railway's edge sets `X-Real-IP`; elsewhere `req.ip` reads `X-Forwarded-For` only from the proxies `trust proxy` names. The web server forwards both when it calls the API for a page. */ |
| 4 | export function clientIp( |
| 5 | request: Pick |
| 6 | onRailway = Boolean( |
| 7 | ) { |
| 8 | const header = |
| 9 | const first = |
| 10 | ?.split(',')[ |
| 11 | ?.trim(); |
| 12 | return first || |
| 13 | } |