@hoajs/cloudflare-rate-limit
v0.2.1
Published
Cloudflare rate limiter middleware for Hoa.
Readme
@hoajs/cloudflare-rate-limit
Cloudflare Rate Limit middleware for Hoa.
Installation
$ npm i @hoajs/cloudflare-rate-limit --saveQuick Start
RateLimiter (using Cloudflare native Rate Limiting API)
import { Hoa } from 'hoa'
import { RateLimiter } from '@hoajs/cloudflare-rate-limit'
const app = new Hoa()
app.use(RateLimiter({
binding: 'RATE_LIMITER',
keyGenerator: (ctx) => ctx.req.ip
}))
app.use(async (ctx) => {
ctx.res.body = 'Hello, Hoa!'
})
export default appKVRateLimiter (using Cloudflare KV)
import { Hoa } from 'hoa'
import { KVRateLimiter } from '@hoajs/cloudflare-rate-limit'
const app = new Hoa()
app.use(KVRateLimiter({
binding: 'KV',
prefix: 'ratelimit:',
limit: 3,
period: 60,
interval: 10,
keyGenerator: (ctx) => ctx.req.ip
}))
app.use(async (ctx) => {
ctx.res.body = 'Hello, Hoa!'
})
export default appDocumentation
The documentation is available on hoa-js.com
Test (100% coverage)
$ npm testLicense
MIT
