Skip to content
Snippets Groups Projects
Unverified Commit a60af43d authored by xgui3783's avatar xgui3783 Committed by GitHub
Browse files

Merge pull request #1162 from FZJ-INM1-BDA/hotfix_saneUrlRateLimiting

hotfix: use redis store for rate limiting
parents 2d5e8b31 b0b521b6
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ const { GitlabSnippetStore: Store, NotFoundError } = require('./store')
const { Store: DepcStore } = require('./depcObjStore')
const RateLimit = require('express-rate-limit')
const RedisStore = require('rate-limit-redis')
const { redisURL } = require('../lruStore')
const lruStore = require('../lruStore')
const { ProxyStore, NotExactlyPromiseAny } = require('./util')
let store
......@@ -23,12 +23,22 @@ const {
DISABLE_LIMITER,
} = process.env
const limiter = new RateLimit({
windowMs: 1e3 * 5,
max: 5,
...( redisURL ? { store: new RedisStore({ redisURL }) } : {} )
})
const passthrough = (_, __, next) => next()
function limiterMiddleware(){
let limiter
return async (req, res, next) => {
if (DISABLE_LIMITER) return next()
if (limiter) return limiter(req, res, next)
await lruStore._initPr
const { redisURL } = lruStore
limiter = new RateLimit({
windowMs: 1e3 * 5,
max: 5,
store: redisURL ? new RedisStore({ redisURL }) : null
})
return limiter(req, res, next)
}
}
const acceptHtmlProg = /text\/html/i
......@@ -85,7 +95,7 @@ router.get('/:name', async (req, res) => {
})
router.post('/:name',
DISABLE_LIMITER ? passthrough : limiter,
limiterMiddleware(),
express.json(),
async (req, res) => {
if (req.headers['x-noop']) return res.status(200).end()
......
......@@ -4,3 +4,7 @@
- Re-enabled autoradiographs for receptor datasets
- Added how-to-cite as a part of quick tour (#1085)
## Bugfix
- saneUrl store now properly uses redis
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment