-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6347 from NMDSdevopsServiceAdm/fix/rate-limiting
Fix/rate limiting
- Loading branch information
Showing
8 changed files
with
512 additions
and
15,013 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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
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 |
---|---|---|
@@ -1,33 +1,31 @@ | ||
|
||
const config = require('../../config/config'); | ||
const RateLimit = require('express-rate-limit'); | ||
const RedisStore = require('rate-limit-redis'); | ||
const expressRateLimit = require('express-rate-limit'); | ||
const { RedisStore } = require('rate-limit-redis'); | ||
const RedisClient = require('ioredis'); | ||
const isCI = require('is-ci'); | ||
|
||
const redisClient = new RedisClient(config.get('redis.url')); | ||
const store = isCI | ||
? undefined | ||
: new RedisStore({ | ||
redisURL: config.get('redis.url'), | ||
sendCommand: (...args) => redisClient.call(...args), | ||
}); | ||
|
||
const rateLimiterConfig = { | ||
store, | ||
delayMs: 0, // disable delaying - full speed until the max limit is reached | ||
passIfNotConnected: true, | ||
windowMs: 60 * 1000, // 1 minute | ||
windowMs: 60 * 1000, // 1 minute | ||
}; | ||
|
||
const authLimiter = isCI | ||
const nhsBsaApiLimiter = isCI | ||
? (req, res, next) => { | ||
next(); | ||
} | ||
: new RateLimit({ | ||
: expressRateLimit.rateLimit({ | ||
...rateLimiterConfig, | ||
max: 100, // maximum number of requests allowed in the windowMs | ||
prefix: 'auth:', | ||
limit: 200, // maximum number of requests allowed in the windowMs | ||
prefix: 'nhsBsaApi:', | ||
}); | ||
|
||
|
||
|
||
module.exports.authLimiter = authLimiter; | ||
|
||
module.exports.nhsBsaApiLimiter = nhsBsaApiLimiter; |