ryanbillingsley / express-ipfilter

A light-weight IP address based connection filtering system
MIT License
109 stars 44 forks source link

Pass the getClientIp function to the custom detectIp function #57

Closed alaycock closed 6 years ago

alaycock commented 6 years ago

My intention is to allow custom detectIp functions to fallback or build on the default implementation if they need to.

I included my yarn.lock, if you prefer not to use it, I can pull it out.

ryanbillingsley commented 6 years ago

@alaycock what kind of use case were you looking at for this?

alaycock commented 6 years ago

My use case is that I want to detect the IP through the application headers if the header exists. But there's a chance the header won't exist, and if it doesn't, I'd like to fall back to the default implementation.

After giving it a bit more thought, I realized it probably makes more sense to export getClientIp from the package than to include it in the function call to detectIp.

Did you have thoughts on a preferred approach, if it's necessary at all?

pdefreitas commented 6 years ago

This is very useful for scenarios where we're behind a reverse proxy. Example: http://expressjs.com/en/guide/behind-proxies.html

alaycock commented 6 years ago

Thanks for commenting on this @pdefreitas, my solution probably isn't the best option. A better solution might be to export the getClientIp function, rather than passing it in as a function argument. Perhaps a project contributor could chime in, but I'm going to close this PR in favour of someone else creating a PR to export it instead.