mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-06 05:26:54 +08:00
moved country middleware to auth to get access to base url and route path
This commit is contained in:
parent
c29ac5ff44
commit
61626aa44d
2 changed files with 10 additions and 10 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue