MCPcopy Create free account
hub / github.com/InsForge/InsForge / parseTrustProxySetting

Function parseTrustProxySetting

backend/src/utils/trust-proxy.ts:5–32  ·  view source on GitHub ↗
(value = process.env.TRUST_PROXY)

Source from the content-addressed store, hash-verified

3export type TrustProxySetting = boolean | number | string;
4
5export 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}

Callers 2

loadConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected