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:
parent
9fbed4c29d
commit
169bf770b6
1 changed files with 13 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue