| Total Complexity | 1 |
| Complexity/F | 1 |
| Lines of Code | 21 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { ExpressMiddlewareInterface, Middleware } from "routing-controllers"; |
||
| 2 | import rateLimit, { RateLimit } from "express-rate-limit"; |
||
| 3 | |||
| 4 | @Middleware({ type: "before" }) |
||
| 5 | export class RateLimitMiddleware implements ExpressMiddlewareInterface { |
||
| 6 | |||
| 7 | private limiter: RateLimit; |
||
| 8 | |||
| 9 | constructor() { |
||
| 10 | this.limiter = rateLimit({ |
||
| 11 | windowMs: parseInt(process.env.RATE_WINDOW) * 1000, // per second |
||
| 12 | max: parseInt(process.env.RATE_MAX), |
||
| 13 | }); |
||
| 14 | } |
||
| 15 | |||
| 16 | public use(req: any, res: any, next: (err?: any) => any): any { |
||
| 17 | return this.limiter(req, res, next); |
||
| 18 | } |
||
| 19 | |||
| 20 | } |
||
| 21 |