limitly 1.0.1 → 1.0.2
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 +10 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# limitly
|
|
2
2
|
|
|
3
3
|
Distributed, Redis-powered rate limiting for Express and Fastify.
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ Distributed, Redis-powered rate limiting for Express and Fastify.
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install
|
|
10
|
+
npm install limitly ioredis
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
@@ -17,7 +17,7 @@ npm install redislimit ioredis
|
|
|
17
17
|
```typescript
|
|
18
18
|
import express from "express";
|
|
19
19
|
import Redis from "ioredis";
|
|
20
|
-
import { createLimiter } from "
|
|
20
|
+
import { createLimiter } from "limitly";
|
|
21
21
|
|
|
22
22
|
const app = express();
|
|
23
23
|
const redis = new Redis();
|
|
@@ -29,7 +29,7 @@ app.use(
|
|
|
29
29
|
limit: 100,
|
|
30
30
|
window: 60,
|
|
31
31
|
key: (req) => req.ip,
|
|
32
|
-
})
|
|
32
|
+
}),
|
|
33
33
|
);
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -38,7 +38,7 @@ app.use(
|
|
|
38
38
|
```typescript
|
|
39
39
|
import Fastify from "fastify";
|
|
40
40
|
import Redis from "ioredis";
|
|
41
|
-
import { createLimiter } from "
|
|
41
|
+
import { createLimiter } from "limitly";
|
|
42
42
|
|
|
43
43
|
const fastify = Fastify();
|
|
44
44
|
const limiter = createLimiter({ redis: new Redis() });
|
|
@@ -103,13 +103,13 @@ createLimiter({
|
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
105
|
// IP-based
|
|
106
|
-
key: (req) => req.ip
|
|
106
|
+
key: (req) => req.ip;
|
|
107
107
|
|
|
108
108
|
// API Key
|
|
109
|
-
key: (req) => req.headers["x-api-key"]
|
|
109
|
+
key: (req) => req.headers["x-api-key"];
|
|
110
110
|
|
|
111
111
|
// User ID
|
|
112
|
-
key: (req) => req.user.id
|
|
112
|
+
key: (req) => req.user.id;
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
## Response Headers
|
|
@@ -145,7 +145,7 @@ When Redis is unavailable:
|
|
|
145
145
|
```typescript
|
|
146
146
|
createLimiter({
|
|
147
147
|
redis: new Redis(),
|
|
148
|
-
failOpen: true,
|
|
148
|
+
failOpen: true, // allow traffic (default)
|
|
149
149
|
// failOpen: false, // block with 503
|
|
150
150
|
});
|
|
151
151
|
```
|
|
@@ -169,4 +169,4 @@ interface RateLimitStrategy {
|
|
|
169
169
|
|
|
170
170
|
## License
|
|
171
171
|
|
|
172
|
-
MIT
|
|
172
|
+
MIT
|