Skip to content

Extract shared createRateLimiter factory - #1141

Open
Peolite001 wants to merge 1 commit into
LabsCrypt:mainfrom
Peolite001:fix-rate-limiter-1099
Open

Extract shared createRateLimiter factory#1141
Peolite001 wants to merge 1 commit into
LabsCrypt:mainfrom
Peolite001:fix-rate-limiter-1099

Conversation

@Peolite001

Copy link
Copy Markdown

Description

This PR addresses issue #1099 by extracting a shared createRateLimiter(options) factory. This consolidates the standard rate limiter configuration into a single location so that both globalRateLimiter and streamCreationRateLimiter use a uniform setup. This prevents duplication and ensures any future bug fixes or config updates (such as a Redis store setup or IP-keying fixes) will apply consistently to all rate limiters without needing manual syncing across multiple files.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or update

Related Issues

Closes #1099

Changes Made

  • Created a createRateLimiter(options) factory in backend/src/middleware/rate-limiter.middleware.ts that includes the shared base config (standardHeaders, legacyHeaders).
  • Updated globalRateLimiter to utilize this new factory instead of a raw rateLimit() call.
  • Imported and utilized createRateLimiter in backend/src/middleware/stream-rate-limiter.middleware.ts for the createStreamRateLimiter factory.

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Steps

  1. Run the existing rate-limiter tests to ensure they still pass successfully with the refactored middleware implementation.
  2. Verify normal application usage, confirming that rate limit headers are still being properly appended and returned to clients.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have checked for breaking changes and documented them if applicable

Additional Notes

This PR specifically focuses on the refactoring requested in the issue. Fixing the trust-proxy IP-keying issue itself and switching rate-limit backends are out of scope for this change and will be addressed in separate PRs/issues as tracked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] backend/src/middleware/rate-limiter.middleware.ts and stream-rate-limiter.middleware.ts duplicate the same window/store setup logic

1 participant