Cloudflare Rate Limit middleware for Hoa.
$ npm i @hoajs/cloudflare-rate-limit --saveimport { 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 appimport { 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 appThe documentation is available on hoa-js.com
$ npm testMIT