not-node 6.3.21 → 6.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/env.js +1 -1
- package/src/init/lib/rateLimiter.js +37 -7
- package/src/manifest/route.js +3 -3
package/package.json
CHANGED
package/src/env.js
CHANGED
|
@@ -22,7 +22,7 @@ module.exports = class notEnv {
|
|
|
22
22
|
* Setting application environment variable
|
|
23
23
|
* @param {string} key name of var
|
|
24
24
|
* @param {object} val value
|
|
25
|
-
* @return
|
|
25
|
+
* @return {notEnv} chainable
|
|
26
26
|
*/
|
|
27
27
|
static setEnv(key, val) {
|
|
28
28
|
ENVS[key] = val;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const log = require("not-log")(module, "RateLimiter");
|
|
2
2
|
const { partCopyObj } = require("../../common");
|
|
3
|
+
const notEnv = require("../../env");
|
|
4
|
+
const { RateLimiterRedis } = require("rate-limiter-flexible");
|
|
3
5
|
|
|
4
6
|
const DEFAULT_OPTIONS = {
|
|
5
7
|
keyPrefix: "rateLimiterMiddleware",
|
|
@@ -44,15 +46,43 @@ module.exports = class InitRateLimiter {
|
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
static createRateLimiter({
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
"modules.rateLimiter.client",
|
|
51
|
-
DEFAULT_CLIENT
|
|
49
|
+
static createRateLimiter({ config }) {
|
|
50
|
+
const storeClient = InitRateLimiter.getClient(
|
|
51
|
+
InitRateLimiter.getClientName({ config })
|
|
52
52
|
);
|
|
53
53
|
return new RateLimiterRedis({
|
|
54
|
-
storeClient
|
|
55
|
-
...InitRateLimiter.getOptions({
|
|
54
|
+
storeClient,
|
|
55
|
+
...InitRateLimiter.getOptions({ config }),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns redis client name in "db.*" of notEnv
|
|
61
|
+
*
|
|
62
|
+
* @static
|
|
63
|
+
* @param {object} { config }
|
|
64
|
+
* @return {string}
|
|
65
|
+
*/
|
|
66
|
+
static getClientName({ config }) {
|
|
67
|
+
return config.get("modules.rateLimiter.client", DEFAULT_CLIENT);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static getClient(storeClient) {
|
|
71
|
+
return notEnv.getEnv(`db.${storeClient}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static initCustom(
|
|
75
|
+
options = {
|
|
76
|
+
keyPrefix: "rateLimiterCustom",
|
|
77
|
+
points: 20,
|
|
78
|
+
duration: 1,
|
|
79
|
+
},
|
|
80
|
+
storeName = DEFAULT_CLIENT
|
|
81
|
+
) {
|
|
82
|
+
const storeClient = InitRateLimiter.getClient(storeName);
|
|
83
|
+
return new RateLimiterRedis({
|
|
84
|
+
storeClient,
|
|
85
|
+
...options,
|
|
56
86
|
});
|
|
57
87
|
}
|
|
58
88
|
};
|
package/src/manifest/route.js
CHANGED
|
@@ -71,7 +71,7 @@ class notRoute {
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Select rule from available or return null
|
|
74
|
-
* @param {import('../types').
|
|
74
|
+
* @param {import('../types').notNodeExpressRequest} req Express Request Object
|
|
75
75
|
* @return {import('../types').notRouteRule | null} rule or null
|
|
76
76
|
*/
|
|
77
77
|
selectRule(req) {
|
|
@@ -85,7 +85,7 @@ class notRoute {
|
|
|
85
85
|
/**
|
|
86
86
|
*
|
|
87
87
|
*
|
|
88
|
-
* @param {import('../types').
|
|
88
|
+
* @param {import('../types').notNodeExpressRequest} req
|
|
89
89
|
* @param {import('../types').notRouteData} notRouteData
|
|
90
90
|
* @memberof notRoute
|
|
91
91
|
*/
|
|
@@ -112,7 +112,7 @@ class notRoute {
|
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* Executes route action if such exist
|
|
115
|
-
* @param {import('../types').
|
|
115
|
+
* @param {import('../types').notNodeExpressRequest} req Express Request Object
|
|
116
116
|
* @param {import('express').Response} res Express Response Object
|
|
117
117
|
* @param {function} next
|
|
118
118
|
* @return {object} result of execution or HttpError
|