fastify/fastify-rate-limit

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

Open

#420 创建于 2025年8月13日

在 GitHub 查看
 (6 评论) (1 反应) (0 负责人)JavaScript (594 star) (76 fork)auto 404
good first issue

描述

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

贡献者指南