Skip to content

Commit a7df756

Browse files
committed
improved version
1 parent 03bfdfb commit a7df756

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

apps/api/src/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ const app = express();
1717

1818
// added trust proxy
1919
const rawTrustProxy = process.env.TRUST_PROXY;
20-
const TRUST_PROXY =
21-
rawTrustProxy && rawTrustProxy !== "false"
22-
? isNaN(Number(rawTrustProxy))
23-
? rawTrustProxy === "true"
24-
? true
25-
: rawTrustProxy
26-
: Number(rawTrustProxy)
27-
: 1;
20+
let TRUST_PROXY: boolean | number | string;
21+
22+
if (!rawTrustProxy) {
23+
TRUST_PROXY = 1;
24+
} else if (rawTrustProxy === "false") {
25+
TRUST_PROXY = false;
26+
} else if (rawTrustProxy === "true") {
27+
TRUST_PROXY = true;
28+
} else if (!isNaN(Number(rawTrustProxy))) {
29+
TRUST_PROXY = Number(rawTrustProxy);
30+
} else {
31+
TRUST_PROXY = rawTrustProxy;
32+
}
2833

2934
app.set("trust proxy", TRUST_PROXY);
3035

0 commit comments

Comments
 (0)