Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions backend/src/middlewares/rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import MonkeyError from "../utils/error";
import type { Response, NextFunction, Request } from "express";
import { RateLimiterMemory } from "rate-limiter-flexible";
import {
ipKeyGenerator,
rateLimit,
RateLimitRequestHandler,
type Options,
Expand Down Expand Up @@ -40,12 +41,13 @@ export const customHandler = (
};

const getKey = (req: Request, _res: Response): string => {
return (
const ip =
(req.headers["cf-connecting-ip"] as string) ||
(req.headers["x-forwarded-for"] as string) ||
(req.ip as string) ||
"255.255.255.255"
);
"255.255.255.255";
const key = ipKeyGenerator(ip);
return key;
};

const getKeyWithUid = (
Expand Down
Loading