Skip to content

Conversation

@kevcomparadise
Copy link
Contributor

@kevcomparadise kevcomparadise commented Nov 13, 2025

per-route rate limiting feature

  • Added support for mixed routes configuration (string and { path, max, duration })
  • Implemented per-route request counting (each route maintains its own counter)
  • Ensured that global fallback limits still apply when no specific route matches
  • Preserved global ban behavior — exceeding any limit will ban the IP across all routes
  • Introduced per-route/IP storage keys to avoid counter collisions between endpoints
  • Added E2E tests
  • Added documentation explaining how to use per-route limits

The following documentation section has been added to the README:

## Per-Route Rate Limiting

`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.

This is useful when certain endpoints (such as `/api/login`, `/api/auth`, or `/api/payment`) require stricter protection.

### Configuration Example

The `routes` option accepts a mixed array:

- **String:** applies the global rate limit configuration
- **Object:** applies custom per-route limits

```ts
export default defineNuxtConfig({
  nuxtApiShield: {
    limit: {
      max: 12,
      duration: 108,
      ban: 3600
    },

    routes: [
      // String → uses global defaults
      '/api/example',

      // Object → custom limit for this route
      {
        path: '/api/example-per-route',
        max: 5,
        duration: 10
        // "ban" remains global
      }
    ],
  }
})

Feel free to share any thoughts or adjustments

Add Per-Route limit configuration feature
@kevcomparadise
Copy link
Contributor Author

Link #120

@rrd108 rrd108 merged commit 3e8beb8 into rrd108:main Nov 14, 2025
2 checks passed
@rrd108
Copy link
Owner

rrd108 commented Nov 14, 2025

Ah thanks, you were really quick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants