Skip to content

Commit 8739306

Browse files
committed
refactor: migrate rate limiting from express-rate-limit to custom Upstash Redis implementation and reorganize configuration files
1 parent c737e8a commit 8739306

15 files changed

Lines changed: 92 additions & 68 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Whether you're summarizing a research paper, technical documentation, blog post,
9898
* Strict payload validation using Zod schemas
9999
* Secure password hashing with bcrypt
100100
* Middleware-based authorization
101-
* Rate limiting on auth and LLM routes via express-rate-limit
101+
* Rate limiting on auth and LLM routes via Upstash Redis
102102

103103
### Infrastructure
104104

@@ -281,7 +281,7 @@ pdf-parse mammoth
281281
* AWS EC2
282282
* GitHub Actions
283283
* Redis
284-
* express-rate-limit
284+
* @upstash/ratelimit
285285

286286
### AI Models
287287

server/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ server/
4040
│ └── scrape.js # URL → scrape → summarize (with Redis caching)
4141
├── middlewares/
4242
│ ├── authMiddleware.js # protectRoute (JWT verification)
43-
│ ├── authRateLimit.js # Rate limiting for auth routes (Upstash Redis)
4443
│ ├── errorHandler.js # Global error handler
45-
│ └── llmRateLimit.js # Rate limiting for LLM/Ingestion routes
44+
│ ├── rateLimiter.js # Rate limit middleware wrapper
45+
│ └── redisRateLimit.js # Upstash Redis instances for auth & ai limiters
4646
├── models/
4747
│ └── User.js # Mongoose user schema
4848
├── routes/

server/package-lock.json

Lines changed: 25 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@cerebras/cerebras_cloud_sdk": "^1.64.1",
1717
"@google/genai": "^2.6.0",
1818
"@mozilla/readability": "^0.6.0",
19+
"@upstash/ratelimit": "^2.0.8",
1920
"@upstash/redis": "^1.38.0",
2021
"axios": "^1.17.0",
2122
"bcrypt": "^6.0.0",
@@ -24,7 +25,6 @@
2425
"crypto": "^1.0.1",
2526
"dotenv": "^17.4.2",
2627
"express": "^5.2.1",
27-
"express-rate-limit": "^8.5.2",
2828
"https": "^1.0.0",
2929
"jsdom": "^29.1.1",
3030
"jsonwebtoken": "^9.0.3",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ const redis = new Redis({
55
token: process.env.UPSTASH_REDIS_REST_TOKEN,
66
});
77

8-
export default redis;
8+
export default redis;

server/src/controllers/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import bcrypt from "bcrypt";
22
import jwt from "jsonwebtoken";
33
import User from "../models/User.js";
4-
import { generateToken } from "../config/utils.js";
4+
import { generateToken } from "../config/generateJWT.js";
55
import { registerSchema, loginSchema } from "../validators/auth.validator.js";
66

77
export const registerUser = async (req, res, next) => {

server/src/controllers/docSummary.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import geminiClient from "../config/llm/geminiClient.js";
33
import cerebrasClient from "../config/llm/cerebrasClient.js";
44
import extractText from "../services/document.js";
55
import sarvamClient from "../config/llm/sarvamClient.js";
6-
import redis from "../services/redis.js";
6+
import redis from "../config/redis.js";
77
import hashContent from "../utils/hashContent.js";
88
import { streamingModels } from "../config/llm/streamingClients.js";
99
import { streamAndCache } from "../utils/streamResponse.js";
1010

1111
const summariseDoc = async (req, res, next) => {
1212
const { client } = req.body;
1313
const shouldStream = req.body.stream === "true" || req.body.stream === true;
14+
1415
const models = {
1516
gemma: gemmaClient,
1617
gemini: geminiClient,

server/src/controllers/scrape.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import geminiClient from "../config/llm/geminiClient.js";
55
import gemmaClient from "../config/llm/gemmaClient.js";
66
import cerebrasClient from "../config/llm/cerebrasClient.js";
77
import sarvamClient from "../config/llm/sarvamClient.js";
8-
import redis from "../services/redis.js";
8+
import redis from "../config/redis.js";
99
import { webSummarySchema } from "../validators/summary.validator.js";
1010
import { streamingModels } from "../config/llm/streamingClients.js";
1111
import { streamAndCache } from "../utils/streamResponse.js";

server/src/middlewares/authRateLimit.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)