diff --git a/backend/src/api/routes/swagger.ts b/backend/src/api/routes/swagger.ts index c1675f538..43e857d77 100644 --- a/backend/src/api/routes/swagger.ts +++ b/backend/src/api/routes/swagger.ts @@ -4,7 +4,6 @@ import swaggerStats from "swagger-stats"; import swaggerUi from "swagger-ui-express"; import publicSwaggerSpec from "../../documentation/public-swagger.json"; import internalSwaggerSpec from "../../documentation/internal-swagger.json"; -import { recordRequestCountry } from "../../utils/prometheus"; const SWAGGER_UI_OPTIONS = { customCss: ".swagger-ui .topbar { display: none } .try-out { display: none }", @@ -33,14 +32,6 @@ function addSwaggerMiddlewares(app: Application): void { swaggerUi.serve, swaggerUi.setup(publicSwaggerSpec, SWAGGER_UI_OPTIONS) ); - - app.use((req, res, next) => { - const country = req.headers["cf-ipcountry"] as string; - if (country) { - recordRequestCountry(country, req as MonkeyTypes.Request); - } - next(); - }); } export default addSwaggerMiddlewares; diff --git a/backend/src/middlewares/auth.ts b/backend/src/middlewares/auth.ts index d362ddd24..f1b696946 100644 --- a/backend/src/middlewares/auth.ts +++ b/backend/src/middlewares/auth.ts @@ -5,7 +5,11 @@ import { verifyIdToken } from "../utils/auth"; import { base64UrlDecode } from "../utils/misc"; import { NextFunction, Response, Handler } from "express"; import statuses from "../constants/monkey-status-codes"; -import { incrementAuth, recordAuthTime } from "../utils/prometheus"; +import { + incrementAuth, + recordAuthTime, + recordRequestCountry, +} from "../utils/prometheus"; import { performance } from "perf_hooks"; interface RequestAuthenticationOptions { @@ -85,6 +89,11 @@ function authenticateRequest(authOptions = DEFAULT_OPTIONS): Handler { req ); + const country = req.headers["cf-ipcountry"] as string; + if (country) { + recordRequestCountry(country, req as MonkeyTypes.Request); + } + next(); }; }