limitwall 1.0.0 → 1.0.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.
- package/README.md +14 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,10 +30,10 @@ import { serve } from "@hono/node-server";
|
|
|
30
30
|
import { Hono } from "hono";
|
|
31
31
|
import { Redis } from "ioredis";
|
|
32
32
|
|
|
33
|
-
import {
|
|
33
|
+
import { NodeRedisStore, rateLimiter } from "limitwall";
|
|
34
34
|
|
|
35
35
|
const app = new Hono();
|
|
36
|
-
const store = new
|
|
36
|
+
const store = new NodeRedisStore({ client: new Redis() });
|
|
37
37
|
|
|
38
38
|
app.use(
|
|
39
39
|
"/api/*",
|
|
@@ -57,14 +57,14 @@ serve(app);
|
|
|
57
57
|
import { Redis } from "@upstash/redis/cloudflare";
|
|
58
58
|
import { Hono } from "hono";
|
|
59
59
|
|
|
60
|
-
import { rateLimiter,
|
|
60
|
+
import { rateLimiter, UpstashRedisStore } from "limitwall";
|
|
61
61
|
|
|
62
62
|
const app = new Hono<{
|
|
63
63
|
Bindings: { UPSTASH_URL: string; UPSTASH_TOKEN: string };
|
|
64
64
|
}>();
|
|
65
65
|
|
|
66
66
|
app.use("/api/*", async (c, next) => {
|
|
67
|
-
const store = new
|
|
67
|
+
const store = new UpstashRedisStore({
|
|
68
68
|
client: new Redis({ url: c.env.UPSTASH_URL, token: c.env.UPSTASH_TOKEN }),
|
|
69
69
|
});
|
|
70
70
|
|
|
@@ -98,18 +98,18 @@ Every algorithm also accepts `ruleName` (required - namespaces its Redis keys) a
|
|
|
98
98
|
## Config reference
|
|
99
99
|
|
|
100
100
|
```ts
|
|
101
|
-
|
|
102
|
-
algorithm: "tokenBucket" | "fixedWindow" | "slidingWindow" | "leakyBucket"
|
|
103
|
-
ruleName: string
|
|
101
|
+
interface RateLimiterConfig {
|
|
102
|
+
algorithm: "tokenBucket" | "fixedWindow" | "slidingWindow" | "leakyBucket";
|
|
103
|
+
ruleName: string;
|
|
104
104
|
// ...algorithm-specific fields, see table above
|
|
105
|
-
cost?: number
|
|
105
|
+
cost?: number;
|
|
106
106
|
|
|
107
|
-
identifier: (c: Context) => string
|
|
108
|
-
store: RateLimitStore
|
|
109
|
-
onError: "fail-open" | "fail-closed"
|
|
110
|
-
headerStyle?: "draft-6" | "draft-7"
|
|
111
|
-
message?: (c: Context) => Response
|
|
112
|
-
}
|
|
107
|
+
identifier: (c: Context) => string; // required - what to rate limit by
|
|
108
|
+
store: RateLimitStore; // NodeRedisStore or UpstashRedisStore
|
|
109
|
+
onError: "fail-open" | "fail-closed"; // required - no silent default
|
|
110
|
+
headerStyle?: "draft-6" | "draft-7"; // defaults to "draft-6"
|
|
111
|
+
message?: (c: Context) => Response; // overrides the default 429 body
|
|
112
|
+
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
## Response headers
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "limitwall",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"description": "Rate limiting middleware for Hono, backed by Redis. Fixed window, sliding window, token bucket, and leaky bucket (GCRA) in one package",
|
|
6
6
|
"author": "Kevin Rozario",
|
|
7
7
|
"license": "MIT",
|