-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.ts
39 lines (34 loc) · 975 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Request, Response, NextFunction } from "express";
import rateLimiter from "express-rate-limit";
export const errorResponse = (code: number, message: string) => {
return {
status: false,
data: null,
error: {
code: code,
message: message,
},
};
};
export const successResponse = (data: any) => {
return {
status: true,
data: data,
};
};
export const generateRandomNumber = () => {
let randomNumber = Math.floor(Math.random() * 1000000000);
return randomNumber;
};
// this thing will not work as we are using lambdas but github scanning recommends to add it!
// also we have rate limiting configured on API GATEWAY side
export const apiLimiter = rateLimiter({
max: 3,
windowMs: 100,
handler: function (req: Request, res: Response, next: NextFunction) {
return res.status(429).json({
error: "You sent too many requests. Please wait a while then try again",
});
},
validate: { ip: false },
});