function getClientIpFromXForwardedFor(value) {
    if (!value) return null

    if (Array.isArray(value)) value = value[0]

    // x-forwarded-for may return multiple IP addresses in the format:
    // "client IP, proxy 1 IP, proxy 2 IP"
    // Therefore, the right-most IP address is the IP address of the most recent proxy
    // and the left-most IP address is the IP address of the originating client.
    // source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
    // Azure Web App's also adds a port for some reason, so we'll only use the first part (the IP)
    const forwardedIps = value.split(',').map((e) => {
        const ip = e.trim()
        if (ip.includes(':')) {
            const splitted = ip.split(':')
            // make sure we only use this if it's ipv4 (ip:port)
            if (splitted.length === 2) {
                return splitted[0]
            }
        }
        return ip
    })

    // Sometimes IP addresses in this header can be 'unknown' (http://stackoverflow.com/a/11285650).
    // Therefore taking the right-most IP address that is not unknown
    // A Squid configuration directive can also set the value to "unknown" (http://www.squid-cache.org/Doc/config/forwarded_for/)
    for (let i = 0; i < forwardedIps.length; i++) {
        if (forwardedIps[i] !== 'unknown') {
            return forwardedIps[i]
        }
    }

    // If no value in the split list is an ip, return null
    return null
}
Parse x-forwarded-for headers.
Borrowed from https://github.com/pbojinov/request-ip/blob/master/src/index.js
@param {string|string[]} value - The value to be parsed.
@returns {string|null} First known IP address, if any.