From 93e8c1b93a8ed1e531550e827ccd203b57036463 Mon Sep 17 00:00:00 2001 From: Shivam Suryawanshi Date: Wed, 22 Oct 2025 22:04:26 +0530 Subject: [PATCH 1/2] Fix validation error --- apps/api/src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 598af42..f958692 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -14,6 +14,20 @@ import ipBlocker from "./middleware/ipBlock.js"; dotenv.config(); const app = express(); + +// added trust proxy +const rawTrustProxy = process.env.TRUST_PROXY; +const TRUST_PROXY = + rawTrustProxy && rawTrustProxy !== "false" + ? isNaN(Number(rawTrustProxy)) + ? rawTrustProxy === "true" + ? true + : rawTrustProxy + : Number(rawTrustProxy) + : 1; + +app.set("trust proxy", TRUST_PROXY); + const PORT = process.env.PORT || 4000; const CORS_ORIGINS = process.env.CORS_ORIGINS ? process.env.CORS_ORIGINS.split(",") From a7df75627725d1c4df5467af4ec753b0e20033b2 Mon Sep 17 00:00:00 2001 From: Shivam Suryawanshi Date: Wed, 22 Oct 2025 22:26:50 +0530 Subject: [PATCH 2/2] improved version --- apps/api/src/index.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index f958692..c01e127 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -17,14 +17,19 @@ const app = express(); // added trust proxy const rawTrustProxy = process.env.TRUST_PROXY; -const TRUST_PROXY = - rawTrustProxy && rawTrustProxy !== "false" - ? isNaN(Number(rawTrustProxy)) - ? rawTrustProxy === "true" - ? true - : rawTrustProxy - : Number(rawTrustProxy) - : 1; +let TRUST_PROXY: boolean | number | string; + +if (!rawTrustProxy) { + TRUST_PROXY = 1; +} else if (rawTrustProxy === "false") { + TRUST_PROXY = false; +} else if (rawTrustProxy === "true") { + TRUST_PROXY = true; +} else if (!isNaN(Number(rawTrustProxy))) { + TRUST_PROXY = Number(rawTrustProxy); +} else { + TRUST_PROXY = rawTrustProxy; +} app.set("trust proxy", TRUST_PROXY);