Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (app, db) {
}
var lookups = opts.lookup.map(function (item) {
return item + ':' + item.split('.').reduce(function (prev, cur) {
return prev[cur]
return prev ? prev[cur] : undefined
}, req)
}).join(':')
var path = opts.path || req.path
Expand Down
19 changes: 19 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ describe('rate-limiter', function () {
done(e)
})
})

it('should work with undefined lookups', function (done) {
limiter({
path: '/route',
method: 'get',
lookup: ['doesNotExist.remoteAddress', 'connection.doesNotExist'],
total: 0,
expire: 1000 * 60 * 60,
skipHeaders: true
})

app.get('/route', function (req, res) {
res.send(200, 'hello')
})

request(app)
.get('/route')
.expect(429, done)
})
})

context('direct middleware', function () {
Expand Down