@jfungus/ratelimit-h3
H3/Nitro middleware for @jfungus/ratelimit
505
9
| Install | |
|---|---|
npm install @jfungus/ratelimit-h3 |
|
| Latest Version: | 0.0.2 |
| License: | MIT |
| Last Updated: | Feb 7, 2026 |
| Links: | GitHub · npm |
Maintainer: jellyfunugs
@jfungus/ratelimit-h3
Rate limiting middleware for H3 and Nitro.
Installation
npm install @jfungus/ratelimit-h3
Usage
H3
import { createApp, createRouter, eventHandler } from "h3";
import { rateLimiter } from "@jfungus/ratelimit-h3";
const app = createApp();
// Apply rate limiting globally
app.use(
rateLimiter({
limit: 100,
windowMs: 60 * 1000, // 1 minute
}),
);
const router = createRouter();
router.get(
"/",
eventHandler(() => "Hello!"),
);
app.use(router);
Nitro
// server/middleware/ratelimit.ts
import { rateLimiter } from "@jfungus/ratelimit-h3";
export default rateLimiter({
limit: 100,
windowMs: 60 * 1000, // 1 minute
});
Options
| Option | Type | Default | Description |
|---|---|---|---|
limit |
number |
100 |
Max requests per window |
windowMs |
number |
60 * 1000 |
Window size in milliseconds (1 minute) |
algorithm |
"sliding-window" | "fixed-window" |
"sliding-window" |
Rate limiting algorithm |
keyGenerator |
(event: H3Event) => string |
IP-based | Function to generate unique key |
skip |
(event: H3Event) => boolean |
- | Skip rate limiting for certain requests |
handler |
(event: H3Event, info: RateLimitInfo) => void |
429 JSON | Custom rate limit exceeded handler |
store |
Store |
MemoryStore |
Custom storage backend |
Custom Key Generator
import { getHeader } from "h3";
app.use(
rateLimiter({
limit: 100,
windowMs: 60 * 1000,
keyGenerator: (event) => {
// Rate limit by API key
return getHeader(event, "x-api-key") || "anonymous";
},
}),
);
Distributed Storage
For multi-instance deployments, use @jfungus/ratelimit-unstorage:
import { createStorage } from "unstorage";
import redisDriver from "unstorage/drivers/redis";
import { createUnstorageStore } from "@jfungus/ratelimit-unstorage";
const storage = createStorage({
driver: redisDriver({ url: "redis://localhost:6379" }),
});
app.use(
rateLimiter({
limit: 100,
windowMs: 60 * 1000,
store: createUnstorageStore({ storage }),
}),
);
Nuxt
For Nuxt applications, use the dedicated module @jfungus/ratelimit-nuxt instead.
Documentation
License
MIT
Related Packages
@drzl/generator-h3
Generate h3 and Nitro route handlers from a Drizzle schema, one module per table...
1,641
110
nuxt-authorization
Authorization module for managing permissions on the Nuxt app and the Nitro serv...
188,002
360
Version History
| Version | Released | License |
|---|---|---|
| 0.0.2 | MIT | |
| 0.0.1 | MIT |