MCPcopy Create free account
hub / github.com/avoidwork/tenso / rate

Function rate

src/middleware/rate.js:17–37  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

15 * @returns {void}
16 */
17export function rate (req, res, next) {
18 const config = req.server.rate;
19
20 if (config.enabled === false || req.unprotect) {
21 next();
22 } else {
23 const results = req.server.rateLimit(req, config.override),
24 good = results.shift();
25
26 if (good) {
27 for (const [idx, i] of rateHeaders.entries()) {
28 res.header(i, results[idx]);
29 }
30
31 next();
32 } else {
33 res.header(RETRY_AFTER, config.reset);
34 res.error(config.status || INT_429);
35 }
36 }
37}

Callers 2

zuulFunction · 0.90

Calls 2

rateLimitMethod · 0.80
headerMethod · 0.80

Tested by

no test coverage detected