More fixes for geoip stuff.

This commit is contained in:
Nick Winter 2015-08-08 11:28:39 -07:00
parent 79ea3258f1
commit b8da7f547f

View file

@ -84,7 +84,7 @@ setupChinaRedirectMiddleware = (app) ->
speaksChinese = firstLanguage and firstLanguage.indexOf('zh') isnt -1
unless config.tokyo
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 = ip?.split(/,? /)[0] # If there are two IP addresses, say because of CloudFlare, we just take the first.
geo = geoip.lookup(ip)
if speaksChinese or geo?.country is "CN"
log.info("Should we redirect to Tokyo server? speaksChinese: #{speaksChinese}, firstLanguage: #{firstLanguage}, ip: #{ip}, geo: #{geo} -- so redirecting? #{geo?.country is 'CN' and speaksChinese}")