All files / src/web/middleware rateLimiter.ts

57.14% Statements 4/7
100% Branches 0/0
0% Functions 0/1
57.14% Lines 4/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 167x 7x   7x   7x                    
import rateLimit from "express-rate-limit";
import { DependencyInjector } from "../../dependencyInjector";
import ILogger from "../../core/contracts/ILogger";
import { injectables } from "../../core/types/injectables";
 
export const limiter = rateLimit({
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 100, // max 100 requests per windowMs
    handler: (req, res, next, options) => {
        const logger = DependencyInjector.Singleton.resolve<ILogger>(injectables.ILogger);
 
        logger.warn(`Rate limit reached`, { ip: req.ip, path: req.path });
 
        res.status(options.statusCode).end(options.message);
    }
});