You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -258,6 +258,49 @@ export default defineTask({
258
258
```
259
259
Make sure to configure `ipTTL` in your `nuxt.config.ts` under `nuxtApiShield` if you wish to use a value different from the default (7 days). Setting `ipTTL: 0` (or any non-positive number) in your config will disable this cleanup task. The `RateLimit` type should be available via `#imports` if your module exports it or makes it available to Nuxt's auto-import system.
260
260
261
+
## Per-Route Rate Limiting
262
+
263
+
`nuxt-api-shield` supports **per-route rate limiting**, allowing you to define custom limits for specific API endpoints while keeping a global default configuration for all other routes.
264
+
265
+
This is useful when certain endpoints (such as `/api/login`, `/api/auth`, or `/api/payment`) require stricter protection.
266
+
267
+
---
268
+
269
+
### Configuration Example
270
+
271
+
The `routes` option accepts a mixed array:
272
+
273
+
-**String:** applies the **global rate limit configuration**
274
+
-**Object:** applies **custom per-route limits**
275
+
276
+
```ts
277
+
exportdefaultdefineNuxtConfig({
278
+
modules: ['nuxt-api-shield'],
279
+
280
+
nuxtApiShield: {
281
+
limit: {
282
+
max: 12,
283
+
duration: 108,
284
+
ban: 3600
285
+
},
286
+
287
+
routes: [
288
+
// 1. String: uses the global default limit
289
+
'/api/example',
290
+
291
+
// 2. Object: custom rate limit for a specific route
0 commit comments