Giter VIP home page Giter VIP logo

hono-rate-limiter's Introduction

🔥hono-rate-limiter🔥

tests npm version npm downloads license

Rate limiting middleware for Hono. Use to limit repeated requests to public APIs and/or endpoints such as password reset.

Warning

The keyGenerator function is currently under construction and needs to be defined for hono-rate-limiter to work properly in your environment. Please ensure that you define the keyGenerator function according to the documentation before using the library.

Usage

import { rateLimiter } from "hono-rate-limiter";

const limiter = rateLimiter({
  windowMs: 15 * 60 * 1000, // 15 minutes
  limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
  standardHeaders: "draft-6", // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
  keyGenerator: (c) => "<unique_key>", // Method to generate custom identifiers for clients.
  // store: ... , // Redis, MemoryStore, etc. See below.
});

// Apply the rate limiting middleware to all requests.
app.use(limiter);

Data Stores

hono-rate-limit supports external data stores to synchronize hit counts across multiple processes and servers.

By default, MemoryStore is used. This one does not synchronize its state across instances. It’s simple to deploy, and often sufficient for basic abuse prevention, but will be inconnsistent across reboots or in deployments with multiple process or servers.

Deployments requiring more consistently enforced rate limits should use an external store.

Here is a list of stores:

Name Description
MemoryStore (default) Simple in-memory option. Does not share state when the app has multiple processes or servers.
@hono-rate-limiter/redis A Redis-backed store, used with @vercel/kv and @upstash/redis
rate-limit-redis A Redis-backed store, more suitable for large or demanding deployments.
rate-limit-postresql A PostgreSQL-backed store.
rate-limit-memecached A Memcached-backed store.
cluster-memory-store A memory-store wrapper that shares state across all processes on a single server via the node:cluster module. Does not share state across multiple servers.
precise-memory-rate-limit A memory store similar to the built-in one, except that it stores a distinct timestamp for each key.
typeorm-rate-limit-store Supports a variety of databases via TypeORM: MySQL, MariaDB, CockroachDB, SQLite, Microsoft SQL Server, Oracle, SAP Hana, and more.
@rlimit/storage A distributed rlimit store, ideal for multi-regional deployments.

Take a look at this guide if you wish to create your own store.

Contributing

We would love to have more contributors involved!

To get started, please read our Contributing Guide.

Credits

The hono-rate-limiter project is heavily inspired by express-rate-limit

hono-rate-limiter's People

Contributors

mathuraditya724 avatar gajendra-singh-r avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.