Package Exports
- hapi-rate-limit
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hapi-rate-limit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
hapi-rate-limit
Lead Maintainer: Gar
Introduction
hapi-rate-limit is a plugin for hapi that enables rate limiting.
It relies on cache
being defined in the server.
Use
const Hapi = require('hapi');
const server = new Hapi.Server({
cache: { engine: require('catbox-memory') }
});
server.connection();
server.register({
register: require('hapi-rate-limit'),
options: {}
});
Options
Defaults are given here
userLimit
:300
number of total requests a user can make per period. Set tofalse
to disable limiting requests per user.pathLimit
:50
number of total requests that can be made on a given path per period. Set tofalse
to disable limiting requests per user.userCache
: Object with the following properties:segment
:hapi-rate-limit-user
Name of the cache segment to use for storing user rate limit infoexpiresIn
:600000
Time (in seconds) of period foruserLimit
pathCache
: Object with the following properties:segment
:hapi-rate-limit-path
Name of the cache segment to use for storing path rate limit infoexpiresIn
:60000
Time (in seconds) of period forpathLimit
headers
:true
Whether or not to include headers in responses
Users
A user is considered a single remoteAddress
for routes that are unauthenticated. On authenticated routes it is the id
attribute of the authenticated user.
Headers
The following headers will be included if their respective limits are enabled
x-ratelimit-pathlimit
: Will equalpathLimit
x-ratelimit-pathremaining
: Remaining number of requests path has this - periodx-ratelimit-pathreset
: Time (in seconds) until reset ofpathLimit
periodx-ratelimit-userlimit
: Will equaluserLimit
x-ratelimit-userremaining
: Remaining number of requests user has this periodx-ratelimit-userreset
: Time (in seconds) until reset ofuserLimit
period
Per-route settings
All of the settings (except for userLimit
and userCache
) can be overridden in your route's config.
For instance, to disable pathLimit
for a route you would add this to its config
attribute
plugins: {
'hapi-rate-limit': {
pathLimit: false
}
}
License: MIT