- Added new configuration options: trustProxy, uploadConcurrency, batchMaxItems, batchMaxSizeBytes, and maxRequestBodyBytes to AppConfig. - Implemented utility functions for parsing environment variables and masking sensitive data. - Updated rate limiting logic to use configurable window size and maximum requests per window. - Introduced a middleware for rate limiting on specific routes. - Refactored file handling routes to support streaming downloads instead of redirects. - Improved error handling and response formatting in file routes. - Added support for oversized request rejection based on Content-Length header. - Updated Swagger documentation to reflect changes in API behavior and responses. - Enhanced tests to cover new features and ensure proper functionality.
17 lines
425 B
TypeScript
17 lines
425 B
TypeScript
import { config } from '../env';
|
|
|
|
export const extractClientIp = (req: Request): string => {
|
|
if (!config.trustProxy) return '127.0.0.1';
|
|
|
|
const forwardedFor = req.headers.get('x-forwarded-for');
|
|
if (forwardedFor) {
|
|
const firstIp = forwardedFor.split(',')[0]?.trim();
|
|
if (firstIp) return firstIp;
|
|
}
|
|
|
|
const realIp = req.headers.get('x-real-ip')?.trim();
|
|
if (realIp) return realIp;
|
|
|
|
return '127.0.0.1';
|
|
};
|