You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this example not works:
// with a function for dynamic-ness
limiter({
lookup: function(req, res, opts, next) {
if (validApiKey(req.query.api_key)) {
opts.lookup = 'query.api_key'
opts.total = 100
} else {
opts.lookup = 'connection.remoteAddress'
opts.total = 10
}
return next()
}
})
app.use('/api', limiter({
lookup: function(req, res, opts, next) {
opts.lookup = 'connection.remoteAddress';
opts.total = 1000;
return next();
},
}));
Got TypeError: opts.lookup is not a function
The text was updated successfully, but these errors were encountered:
Well, lookup is a property of the opts object. And application reassign that property to the string later in the code (opts.lookup = 'connection.remoteAddress';).
I suggest, as a quick patch, to cache an initial function (opts.lookup) and reuse it in line 53 (I'm using v1.6.0)
if (typeof(opts.lookup) === 'function') {
const _cachedLookup = opts.lookup; // cache provided function
middleware = function (middleware, req, res, next) {
return _cachedLookup(req, res, opts, function () { // reuse cached function
return middleware(req, res, next)
})
}.bind(this, middleware)
}
Hi @ded
Could you cut new release version as current version v1.6.0 (that available through NPM) is missing fix (made by @vamonte ) for described issue?
Thank you.
this example not works:
// with a function for dynamic-ness
limiter({
lookup: function(req, res, opts, next) {
if (validApiKey(req.query.api_key)) {
opts.lookup = 'query.api_key'
opts.total = 100
} else {
opts.lookup = 'connection.remoteAddress'
opts.total = 10
}
return next()
}
})
app.use('/api', limiter({
lookup: function(req, res, opts, next) {
opts.lookup = 'connection.remoteAddress';
opts.total = 1000;
return next();
},
}));
Got TypeError: opts.lookup is not a function
The text was updated successfully, but these errors were encountered: