Rate limiting has been implemented for all upload endpoints to prevent abuse and ensure fair usage of the CDN API.
-
File Upload Endpoint (
/api/file/upload)- Limit: 15 requests per 15 minutes per IP
- Applies to: General file uploads (potentially larger files)
- Response on limit exceeded: HTTP 429 (Too Many Requests)
-
Image Upload Endpoint (
/api/image/upload)- Limit: 30 requests per 15 minutes per IP
- Applies to: Image file uploads specifically
- Response on limit exceeded: HTTP 429 (Too Many Requests)
- Rate limiting is based on IP address
- Each IP address has its own independent counter
- The counter resets after the 15-minute window expires
- Rate limit information is included in response headers:
RateLimit-Limit: Maximum number of requests allowedRateLimit-Remaining: Number of requests remainingRateLimit-Reset: Time when the rate limit resets
When rate limit is exceeded, the API returns:
{
"success": false,
"message": "Too many upload requests from this IP, please try again after 15 minutes",
"data": null
}Status Code: 429 Too Many Requests
The rate limiting configuration can be adjusted in src/server/middlewares/rate-limit.ts:
windowMs: Time window in milliseconds (default: 15 minutes)max: Maximum number of requests per windowkeyGenerator: Function to generate unique keys (default: IP address)
You can modify the skip function in the rate limiter configuration to bypass rate limiting for specific conditions:
skip: (req) => {
// Example: Skip rate limiting for localhost
const trustedIPs = ['127.0.0.1', '::1'];
return trustedIPs.includes(req.ip);
}To adjust the rate limits, modify the max value:
export const fileUploadRateLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 20, // Change this value
// ... other options
});To test rate limiting:
- Make multiple upload requests to the endpoint
- After exceeding the limit, you should receive a 429 status code
- Check the
RateLimit-*headers in the response to see remaining requests
- Always check the
RateLimit-Remainingheader before making requests - Implement exponential backoff when receiving 429 responses
- Consider caching uploaded files to minimize repeat uploads
- For high-volume applications, contact the API administrator for increased limits