forked from github/docs
-
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.
Use Redis Store for rate limiting when available (github#16484)
- Loading branch information
Showing
3 changed files
with
69 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
const rateLimit = require('express-rate-limit') | ||
const RedisStore = require('rate-limit-redis') | ||
|
||
const isProduction = process.env.NODE_ENV === 'production' | ||
const REDIS_URL = process.env.REDIS_URL | ||
|
||
module.exports = rateLimit({ | ||
// 1 minute (or practically unlimited outside of production) | ||
windowMs: isProduction ? (60 * 1000) : 1, | ||
// limit each IP to 20 requests per windowMs | ||
// limit each IP to X requests per windowMs | ||
max: 250, | ||
// Don't rate limit requests for 200s and redirects | ||
// Or anything with a status code less than 400 | ||
skipSuccessfulRequests: true | ||
skipSuccessfulRequests: true, | ||
// When available, use Redis | ||
store: REDIS_URL && new RedisStore({ redisURL: REDIS_URL }) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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