From a54bf556ed1eb55edab45fa9e6147e233ec1004f Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 27 Feb 2024 03:49:03 -0500 Subject: [PATCH] Revert "Fix usercounter behind cloudflare" This reverts commit 9bcceb7e5bc49b17c7e9be6a830705588c90b2cf. --- src/middleware/userCounter.ts | 2 +- src/utils/getIP.ts | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/middleware/userCounter.ts b/src/middleware/userCounter.ts index 5575fd9..eda60a3 100644 --- a/src/middleware/userCounter.ts +++ b/src/middleware/userCounter.ts @@ -12,7 +12,7 @@ export function userCounter(req: Request, res: Response, next: NextFunction): vo if (Math.random() < 1 / config.userCounterRatio) { axios({ method: "post", - url: `${config.userCounterURL}/api/v1/addIP?hashedIP=${getIP(req, true)}`, + url: `${config.userCounterURL}/api/v1/addIP?hashedIP=${getIP(req)}`, httpAgent }).catch(() => /* instanbul skip next */ Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`)); } diff --git a/src/utils/getIP.ts b/src/utils/getIP.ts index eebf586..85a7192 100644 --- a/src/utils/getIP.ts +++ b/src/utils/getIP.ts @@ -2,7 +2,7 @@ import { config } from "../config"; import { Request } from "express"; import { IPAddress } from "../types/segments.model"; -export function getIP(req: Request, checkCloudflare = false): IPAddress { +export function getIP(req: Request): IPAddress { // if in testing mode, return immediately if (config.mode === "test") return "127.0.0.1" as IPAddress; @@ -10,14 +10,11 @@ export function getIP(req: Request, checkCloudflare = false): IPAddress { config.behindProxy = "X-Forwarded-For"; } - const cloudflareIP = req.headers["cf-connecting-ip"] as IPAddress; - if (checkCloudflare && cloudflareIP) return cloudflareIP; - switch (config.behindProxy as string) { case "X-Forwarded-For": return req.headers["x-forwarded-for"] as IPAddress; case "Cloudflare": - return cloudflareIP; + return req.headers["cf-connecting-ip"] as IPAddress; case "X-Real-IP": return req.headers["x-real-ip"] as IPAddress; default: