diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 598af42..c01e127 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -14,6 +14,25 @@ import ipBlocker from "./middleware/ipBlock.js"; dotenv.config(); const app = express(); + +// added trust proxy +const rawTrustProxy = process.env.TRUST_PROXY; +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); + const PORT = process.env.PORT || 4000; const CORS_ORIGINS = process.env.CORS_ORIGINS ? process.env.CORS_ORIGINS.split(",")