Fix: Improve rate limiting configuration for proxy setup

- Added proper keyGenerator for rate limiter to handle proxy IPs
- Prevents rate limiting validation errors behind Caddy proxy
- Should resolve remaining upload issues
This commit is contained in:
TheMaddax 2025-06-25 15:30:26 -05:00
parent 9fbed4c29d
commit 169bf770b6

View file

@ -62,13 +62,22 @@ app.use(cors({
credentials: true,
}));
// Rate limiting
// Rate limiting with proper proxy configuration
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
message: 'Too many requests from this IP, please try again later.',
standardHeaders: true,
legacyHeaders: false,
// Skip rate limiting validation errors in production behind proxy
skip: (req) => {
// Skip rate limiting if we can't determine the real IP
return false;
},
keyGenerator: (req) => {
// Use X-Forwarded-For header if available, otherwise fall back to req.ip
return req.ip || 'unknown';
},
});
app.use('/api', limiter);
@ -80,6 +89,9 @@ const authLimiter = rateLimit({
message: 'Too many authentication attempts, please try again later.',
standardHeaders: true,
legacyHeaders: false,
keyGenerator: (req) => {
return req.ip || 'unknown';
},
});
app.use('/api/auth', authLimiter);