fastify/fastify-rate-limit

Add a way to check the status of rate limiters without incrementing them

Fermée

#420 ouverte le 13 août 2025

 (8 commentaires) (1 réaction) (0 personne assignée)JavaScript (76 forks)auto 404
good first issue

Métriques du dépôt

Stars
 (594 étoiles)
Métriques de merge PR
 (Merge moyen 7j 4h) (7 PRs mergées en 30 j)

Description

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

After creating a rate limiter manually using fastify.createRateLimit(), I can call this limiter as a function. However, this also increments the limiter. I would like a way to just check the current status of the rate limiter without incrementing it.

Here's an example syntax of how it might work:

// Create manual rate limiter
const checkRateLimit = fastify.createRateLimit();

// Check status and increment limiter, like it works today
const limit = await checkRateLimit(request);

// Proposal to only check status without increment. Returns the same as above, but doesn't change the "remaining" property.
const limit = await checkRateLimit(request, { increment: false });

The reason I need this is because I want to apply a rate limiter to my login endpoint specifically, but only want it incremented when the login attempt fails. I still need to check if my limiter has been reached regardless of success/failure, so that I can deny access if it's reached, which is why I need this feature.

Another solution would be a way to reset/modify the "remaining" property manually, so I could reset it when the user successfully logins. Whichever solution is fine by me, but I figured that the ability to check status of a limiter without incrementing it might also be useful for other purposes, such as monitoring.

Motivation

No response

Example

No response

Guide contributeur