Try harder to find the ip address, and dont split the ipaddress if we didnt find it.

This commit is contained in:
Rob Blanckaert 2016-09-07 13:46:45 -07:00
parent 963b82eadd
commit 9619ff5a0a

View file

@ -120,8 +120,8 @@ setupCountryRedirectMiddleware = (app, country="china", countryCode="CN", langua
reqHost ?= req.host
unless reqHost.toLowerCase() is host
ip = req.headers['x-forwarded-for'] or req.connection.remoteAddress
ip = ip?.split(/,? /)[0] # If there are two IP addresses, say because of CloudFlare, we just take the first.
ip = req.headers['x-forwarded-for'] or req.ip or req.connection.remoteAddress
ip = ip?.split(/,? /)[0] if ip? # If there are two IP addresses, say because of CloudFlare, we just take the first.
geo = geoip.lookup(ip)
#if speaksLanguage or geo?.country is countryCode
# log.info("Should we redirect to #{serverID} server? speaksLanguage: #{speaksLanguage}, acceptedLanguages: #{req.acceptedLanguages}, ip: #{ip}, geo: #{geo} -- so redirecting? #{geo?.country is 'CN' and speaksLanguage}")