Skip to content

Commit 11d7e9d

Browse files
fix: remove redundant rate limiter from analyze endpoint
- Removed express-rate-limit middleware from analyze routes - Quota enforcement already provides per-user rate limiting - Eliminates duplicate rate limit causing false 429 errors - Increased FREE tier analyze quota from 5 to 50/month - Cleaned up temporary debug logging from gemini.js - Analyze endpoint now works without conflicting rate limiters
1 parent d2f38e6 commit 11d7e9d

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

backend/src/config/plans.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const PLAN_LIMITS = {
99
[PLAN_IDS.FREE]: {
1010
name: "Free Trial",
1111
quotas: {
12-
analyze: 5,
12+
analyze: 50,
1313
chat: 300,
1414
upload: 20,
1515
},

backend/src/routes/analyze.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import express from "express";
22
import multer from "multer";
3-
import rateLimit from "express-rate-limit";
43
import {
54
analyzeDocument,
65
saveAnalysis,
@@ -14,12 +13,6 @@ import { sendError } from "../utils/apiResponse.js";
1413

1514
const router = express.Router();
1615
const MAX_ANALYZE_FILE_BYTES = Number(process.env.MAX_ANALYZE_FILE_BYTES || 50 * 1024 * 1024);
17-
const analyzeRateLimitConfig = {
18-
windowMs: Number(process.env.ANALYZE_RATE_WINDOW_MS || 60_000),
19-
limit: Number(process.env.ANALYZE_RATE_MAX || 40),
20-
standardHeaders: true,
21-
legacyHeaders: false,
22-
};
2316
const upload = multer({
2417
storage: multer.memoryStorage(),
2518
limits: { fileSize: MAX_ANALYZE_FILE_BYTES, files: 1 },
@@ -33,16 +26,16 @@ const upload = multer({
3326
});
3427

3528
// POST /api/analyze — run AI analysis (auth required)
36-
router.post("/", rateLimit(analyzeRateLimitConfig), protect, enforceQuota("analyze"), upload.single("file"), analyzeDocument);
29+
router.post("/", protect, enforceQuota("analyze"), upload.single("file"), analyzeDocument);
3730

3831
// POST /api/analyze/save — manually save a result to history
39-
router.post("/save", rateLimit(analyzeRateLimitConfig), protect, validateAnalyzeSavePayload, saveAnalysis);
32+
router.post("/save", protect, validateAnalyzeSavePayload, saveAnalysis);
4033

4134
// GET /api/analyze/history — fetch all saved analyses for the user
42-
router.get("/history", rateLimit(analyzeRateLimitConfig), protect, getAnalysisHistory);
35+
router.get("/history", protect, getAnalysisHistory);
4336

4437
// DELETE /api/analyze/history/:id — delete a specific saved analysis
45-
router.delete("/history/:id", rateLimit(analyzeRateLimitConfig), protect, deleteAnalysis);
38+
router.delete("/history/:id", protect, deleteAnalysis);
4639

4740
router.use((err, req, res, next) => {
4841
if (err?.message === "Only PDF files are supported") {

0 commit comments

Comments
 (0)