Passed
Push — master ( 2213af...1dd3aa )
by Leandro
02:53 queued 12s
created

src/middlewares/RateLimitMiddleware.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 21
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 15
mnd 0
bc 0
fnc 1
dl 0
loc 21
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A RateLimitMiddleware.use 0 3 1
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