mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 10:56:53 -05:00
Check all languages instead of just first for country servers
This commit is contained in:
parent
c6bb5b5329
commit
6773f1e876
1 changed files with 2 additions and 3 deletions
|
@ -80,14 +80,13 @@ setupPassportMiddleware = (app) ->
|
||||||
|
|
||||||
setupCountryRedirectMiddleware = (app, country="china", countryCode="CN", languageCode="zh", serverID="tokyo") ->
|
setupCountryRedirectMiddleware = (app, country="china", countryCode="CN", languageCode="zh", serverID="tokyo") ->
|
||||||
shouldRedirectToCountryServer = (req) ->
|
shouldRedirectToCountryServer = (req) ->
|
||||||
firstLanguage = req.acceptedLanguages[0]
|
speaksLanguage = _.any req.acceptedLanguages, (language) -> language.indexOf languageCode isnt -1
|
||||||
speaksLanguage = firstLanguage and firstLanguage.indexOf(languageCode) isnt -1
|
|
||||||
unless config[serverID]
|
unless config[serverID]
|
||||||
ip = req.headers['x-forwarded-for'] or req.connection.remoteAddress
|
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)
|
geo = geoip.lookup(ip)
|
||||||
#if speaksLanguage or geo?.country is countryCode
|
#if speaksLanguage or geo?.country is countryCode
|
||||||
# log.info("Should we redirect to #{serverID} server? speaksLanguage: #{speaksLanguage}, firstLanguage: #{firstLanguage}, ip: #{ip}, geo: #{geo} -- so redirecting? #{geo?.country is 'CN' and speaksLanguage}")
|
# 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}")
|
||||||
return geo?.country is countryCode and speaksLanguage
|
return geo?.country is countryCode and speaksLanguage
|
||||||
else
|
else
|
||||||
#log.info("We are on #{serverID} server. speaksLanguage: #{speaksLanguage}, acceptedLanguages: #{req.acceptedLanguages[0]}")
|
#log.info("We are on #{serverID} server. speaksLanguage: #{speaksLanguage}, acceptedLanguages: #{req.acceptedLanguages[0]}")
|
||||||
|
|
Loading…
Reference in a new issue