| Total Complexity | 1 |
| Total Lines | 15 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { ExpressMiddlewareInterface, Middleware } from "routing-controllers"; |
||
| 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 | } |
||
| 21 |