Allow dependency injection for “is-ip” in “get-client-ip-address” #364
GuptaSiddhant
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently “get-client-ip-address” util accepts only one parameter and uses “is-ip” package to check if the header value is a IP address or not.
But on NodeJS, as pointed out by README of “is-ip” package, there is built in “net.isIP”.
If the api of the util is updated to accept a second predicate parameter which accepts a function to check the if the input is IP.
type PredicateFn = (input: string) => boolean;
User can pass the “isIP” function from “is-ip” package or pass a custom function based on NodeJs net lib.
import net from “node:net”;
const isIP = (input:string) => net.isIP(input) !== 0;
This can reduce one extra dependency for apps that only depend on single type server runtime, since other runtimes may provide their native ip checking function.
Beta Was this translation helpful? Give feedback.
All reactions