-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
875 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = function (app) { | ||
var Controller = { | ||
name: "Webhook", | ||
}; | ||
|
||
// Reset Rate Limit | ||
// @/webhook/ratelimit/reset | ||
Controller.ratelimit_reset = async (req, res) => { | ||
app.config.RateLimit.resetKey(req.ip); | ||
res.json({ message: 'Rate limit is reset!' }); | ||
} | ||
|
||
return Controller; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function (app) { | ||
var WebhookController = app.controllers.Webhook; | ||
app.post("/webhook/ratelimit/reset", [], WebhookController.ratelimit_reset); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,46 @@ | ||
const rateLimit = require('express-rate-limit'); | ||
|
||
/* Rate Limit Reset in minutes */ | ||
const windowM = 15; | ||
|
||
const exemptedEndpoints = [ | ||
'/webhook/ratelimit/reset' | ||
]; | ||
|
||
const RateLimit = rateLimit({ | ||
/* Exempt endpoint from Rate Limiter */ | ||
skip: (req) => exemptedEndpoints.includes(req.url), | ||
|
||
/* 15 minutes */ | ||
windowMs: 15 * 60 * 1000, | ||
windowMs: windowM * 60 * 1000, | ||
|
||
/* Request Limit Per IP Per Window */ | ||
limit: 10000, | ||
limit: 10, | ||
|
||
/* draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header */ | ||
standardHeaders: 'draft-7', | ||
standardHeaders: 'draft-7', | ||
|
||
/* Disable the `X-RateLimit-*` headers */ | ||
legacyHeaders: false, | ||
legacyHeaders: false, | ||
|
||
/* 429 status = Too Many Requests (RFC 6585) */ | ||
statusCode: 429, | ||
|
||
/* Send custom rate limit header with limit and remaining */ | ||
headers: true, | ||
|
||
/* Do not count failed requests (status >= 400) */ | ||
skipFailedRequests: false, | ||
|
||
/* Do not count successful requests (status < 400) */ | ||
skipSuccessfulRequests: false, | ||
|
||
message: { | ||
status: 429, | ||
message: 'Too many requests, please try again later.' | ||
}, | ||
|
||
onLimitReached: function (/*req, res, optionsUsed*/) { } | ||
}) | ||
|
||
module.exports = { RateLimit }; | ||
module.exports = { RateLimit }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.