ITADN

404 Route Rate Limit Configuration Throws TypeError: app.rateLimit is not a function

#389ClosedKMJ-007 创建于 2024-10-29
K
KMJ-007commented
### Prerequisites - [X] I have written a descriptive issue title - [X] I have searched existing issues to ensure the bug has not already been reported ### Fastify version 4.27.0 ### Plugin version 10.0.1 ### Node.js version 21.7.3 ### Operating system macOS ### Operating system version (i.e. 20.04, 11.3, 10) 15.0 ### Description When trying to configure rate limiting for the 404 not found handler using `app.rateLimit()`, the application throws a TypeError indicating that rateLimit is not a function. **Steps to Reproduce** 1. Set up a Fastify application with @fastify/rate-limit plugin 2. Try to use rateLimit in setNotFoundHandler's preHandler **Code Example** ```typescript import fastify from "fastify"; import rateLimit from "@fastify/rate-limit"; const app = fastify(); // Register rate limit plugin app.register(rateLimit, { global: true, max: 1000, timeWindow: "1 minute" }); // This throws TypeError: app.rateLimit is not a function app.setNotFoundHandler( { preHandler: app.rateLimit({ max: 10, timeWindow: "1 minute", errorResponseBuilder: (_, context) => ({ statusCode: 429, error: "Too Many Requests", message: `Too many not found requests. Please try again in ${context.after}` }) }) }, function (_, reply) { reply.code(404).send({ statusCode: 404, error: "Not Found", message: "Route not found" }); } ); ``` **Expected Behavior** The rate limit configuration should work for the 404 not found handler. **Actual Behavior** Application throws TypeError: app.rateLimit is not a function
关闭于 2024-10-30 1 条评论