fix(api): respect RATE_LIMIT_PER_MIN for tool routes (#272)

Tool endpoints (/api/v1/tools/*) now honor the RATE_LIMIT_PER_MIN env var instead of a hardcoded 60/min: `0` disables per-tool limiting, `>0` uses the configured value, and unset falls back to 60. Merged on top of the section-based route refactor (#280).

Fixes #271.
This commit is contained in:
Luciano Godoy
2026-06-21 23:39:55 +08:00
committed by GitHub
parent 5d5117acf7
commit ce02ce1348
2 changed files with 59 additions and 185 deletions
+10 -1
View File
@@ -223,11 +223,20 @@ export function createToolRoute<T>(app: FastifyInstance, config: ToolRouteConfig
};
toolRegistry.set(config.toolId, resolved);
// Set up rate limiting
const toolRateLimit =
env.RATE_LIMIT_PER_MIN === 0
? false
: {
max: env.RATE_LIMIT_PER_MIN || 60, // Keep fallback in case env var is not set
timeWindow: "1 minute",
};
app.post(
config.section
? `/api/v1/tools/${config.section}/${config.toolId}`
: apiToolPath(config.toolId),
{ config: { rateLimit: { max: 60, timeWindow: "1 minute" } } },
{ config: { rateLimit: toolRateLimit } },
async (request: FastifyRequest, reply: FastifyReply) => {
// Check per-tool access before processing uploads
const authUser = getAuthUser(request);