(value = process.env.TRUST_PROXY)
| 3 | export type TrustProxySetting = boolean | number | string; |
| 4 | |
| 5 | export function parseTrustProxySetting(value = process.env.TRUST_PROXY): TrustProxySetting { |
| 6 | if (value === undefined || value.trim() === '') { |
| 7 | return DEFAULT_TRUST_PROXY_HOPS; |
| 8 | } |
| 9 | |
| 10 | const normalized = value.trim().toLowerCase(); |
| 11 | if (normalized === 'true') { |
| 12 | return true; |
| 13 | } |
| 14 | if (normalized === 'false') { |
| 15 | return false; |
| 16 | } |
| 17 | |
| 18 | const hopCount = Number(normalized); |
| 19 | if (Number.isFinite(hopCount)) { |
| 20 | if (Number.isInteger(hopCount) && hopCount >= 0) { |
| 21 | return hopCount; |
| 22 | } |
| 23 | |
| 24 | throw new Error( |
| 25 | 'TRUST_PROXY must be a non-negative integer, boolean, or Express trust proxy string' |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | // Express also accepts named/address trust proxy values such as |
| 30 | // "loopback", "linklocal", "uniquelocal", or comma-separated subnets. |
| 31 | return value.trim(); |
| 32 | } |
no outgoing calls
no test coverage detected