0.2.0 • Published 8 years ago

@rill/rate-limit v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Rate limit middleware for Rill.

Uses Keyv for persistance. Supports caching in memory, mongodb, redis, sqllite, mysql and postgre.

Installation

npm install @rill/rate-limit

Example

app.js

const app = rill()
const limit = require("@rill/rate-limit")

// Setup the middleware. (1000 req/hr max)
app.use(limit({
  max: 1000,
  duration: '1 hour'
}))

Options

{
  /**
   * Key used for keyv namespace.
   */
  key: '@rill/rate-limit',
  /**
   * The maximum amount of requests from a user per period.
   */
  max: 2500,
  /**
   * The duration of a period. (in ms or as a string).
   */
  duration: '1 hour',
  /**
   * Overrride the identifier for the users (default is their ip addresss).
   */
  id: ctx => ctx.req.ip,
  /**
   * Passed to keyv, do not send this to client.
   * Mongo db example. (must have installed keyv-mongo).
   */
  cache: !process.brower && {
    uri: 'mongodb://user:pass@localhost:27017/dbname' // Default is in memory (see keyv uri).
  }
}

Contributions

  • Use npm test to run tests.

Please feel free to create a PR!

0.2.0

8 years ago

0.1.0

8 years ago