Created
January 19, 2021 08:13
-
-
Save petrosDemetrakopoulos/e62f4b11259af7dfb9630ddbf68c6c18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var rateLimit = require("express-rate-limit"); | |
app.set('trust proxy', 1); // add this line only if your server is behind a proxy | |
var limiter = rateLimit({ | |
windowMs: 15 * 60 * 1000, // 15 minutes | |
max: 100, // limit each IP to 100 requests per windowMs | |
delayMs: 0 // disable delaying - user has full speed until the max limit is reached | |
}); | |
app.use(limiter); // applies rate limiting policy to every endpoint of the server | |
// we could also apply policies for specific routes or even different policies for each route |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment