Skip to content

refactor: extract duplicated code getClientIp#234

Open
k05j wants to merge 1 commit intotiagozip:mainfrom
k05j:refactor/extract-getClientIp
Open

refactor: extract duplicated code getClientIp#234
k05j wants to merge 1 commit intotiagozip:mainfrom
k05j:refactor/extract-getClientIp

Conversation

@k05j
Copy link
Copy Markdown

@k05j k05j commented Apr 22, 2026

  • extracting the client ip was duplicated in cap.js and ratelimit.js (called generator). Any future changes would require updating both.
  • introduced new file ip_extraction that exports the function getClientIp, the function is then imported in cap.js and ratelimit.js
  • dropped one warning in ratelimiter that the IP could not be found in the header because it is duplicated, as we log "Unable to determine client IP" anyways if it cannot be found

I noticed the duplication in code while reading through and thought it would help in the future.

* getting the client ip was duplicated in cap.js and ratelimit.js which
  meant that if it needs changes in the future we would have to change
two functions that effectively do the same
* introduced new file ip_extraction that exports the function
  getClientIp, the function is then imported in cap.js and ratelimit.js
* dropped one warning in ratelimiter that the IP could not be found in
  the header because it is duplicated, as we log "Unable to determine
client IP" anyways if it cannot be found
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.

1 participant