hono-rate-limiter 0.2.1-rc.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +66 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ <h1 align="center"> <code>🔥hono-rate-limiter🔥</code> </h1>
2
+
3
+ <div align="center">
4
+
5
+ [![tests](https://img.shields.io/github/actions/workflow/status/rhinobase/hono-rate-limiter/test.yaml)](https://github.com/rhinobase/hono-rate-limiter/actions/workflows/test.yaml)
6
+ [![npm version](https://img.shields.io/npm/v/hono-rate-limiter.svg)](https://npmjs.org/package/hono-rate-limiter "View this project on NPM")
7
+ [![npm downloads](https://img.shields.io/npm/dm/hono-rate-limiter)](https://www.npmjs.com/package/hono-rate-limiter)
8
+ [![license](https://img.shields.io/npm/l/hono-rate-limiter)](LICENSE)
9
+
10
+ </div>
11
+
12
+ Rate limiting middleware for [Hono](https://hono.dev/). Use to
13
+ limit repeated requests to public APIs and/or endpoints such as password reset.
14
+
15
+ > [!WARNING]
16
+ > 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.
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ import { rateLimiter } from "hono-rate-limiter";
22
+
23
+ const limiter = rateLimiter({
24
+ windowMs: 15 * 60 * 1000, // 15 minutes
25
+ limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
26
+ standardHeaders: "draft-6", // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
27
+ keyGenerator: () => "<unique_key>", // Method to generate custom identifiers for clients.
28
+ // store: ... , // Redis, MemoryStore, etc. See below.
29
+ });
30
+
31
+ // Apply the rate limiting middleware to all requests.
32
+ app.use(limiter);
33
+ ```
34
+
35
+ # Data Stores
36
+
37
+ `hono-rate-limit` supports external data stores to synchronize hit counts across multiple processes and servers.
38
+
39
+ 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.
40
+
41
+ Deployments requiring more consistently enforced rate limits should use an external store.
42
+
43
+ Here is a list of stores:
44
+
45
+ | Name | Description |
46
+ | ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
47
+ | MemoryStore | (default) Simple in-memory option. Does not share state when the app has multiple processes or servers. |
48
+ | [`rate-limit-redis`](https://npm.im/rate-limit-redis) | A [Redis](https://redis.io/)-backed store, more suitable for large or demanding deployments. |
49
+ | [`rate-limit-postresql`](https://www.npm.im/@acpr/rate-limit-postgresql) | A [PostgreSQL](https://www.postgresql.org/)-backed store. |
50
+ | [`rate-limit-memecached`](https://npmjs.org/package/rate-limit-memcached) | A [Memcached](https://memcached.org/)-backed store. |
51
+ | [`cluster-memory-store`](https://npm.im/@express-rate-limit/cluster-memory-store) | A memory-store wrapper that shares state across all processes on a single server via the [node:cluster](https://nodejs.org/api/cluster.html) module. Does not share state across multiple servers. |
52
+ | [`precise-memory-rate-limit`](https://www.npm.im/precise-memory-rate-limit) | A memory store similar to the built-in one, except that it stores a distinct timestamp for each key. |
53
+ | [`typeorm-rate-limit-store`](https://www.npmjs.com/package/typeorm-rate-limit-store) | Supports a variety of databases via [TypeORM](https://typeorm.io/): MySQL, MariaDB, CockroachDB, SQLite, Microsoft SQL Server, Oracle, SAP Hana, and more. |
54
+ | [`@rlimit/storage`](https://www.npmjs.com/package/@rlimit/storage) | A distributed rlimit store, ideal for multi-regional deployments. |
55
+
56
+ Take a look at this [guide](https://express-rate-limit.mintlify.app/guides/creating-a-store) if you wish to create your own store.
57
+
58
+ # Contributing
59
+
60
+ We would love to have more contributors involved!
61
+
62
+ To get started, please read our [Contributing Guide](https://github.com/rhinobase/hono-rate-limiter/blob/main/CONTRIBUTING.md).
63
+
64
+ # Credits
65
+
66
+ The `hono-rate-limiter` project is heavily inspired by [express-rate-limit](https://github.com/express-rate-limit/express-rate-limit)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono-rate-limiter",
3
- "version": "0.2.1-rc.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "hono",