mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Debugging chinaVersion inconsistencies.
This commit is contained in:
parent
8cffb68462
commit
e43addf55b
2 changed files with 6 additions and 1 deletions
|
@ -7,6 +7,7 @@ config = require '../../server_config'
|
|||
errors = require '../commons/errors'
|
||||
languages = require '../routes/languages'
|
||||
sendwithus = require '../sendwithus'
|
||||
log = require 'winston'
|
||||
|
||||
module.exports.setup = (app) ->
|
||||
authentication.serializeUser((user, done) -> done(null, user._id))
|
||||
|
@ -198,9 +199,10 @@ module.exports.loginUser = loginUser = (req, res, user, send=true, next=null) ->
|
|||
|
||||
module.exports.makeNewUser = makeNewUser = (req) ->
|
||||
user = new User({anonymous: true})
|
||||
user.set 'testGroupNumber', Math.floor(Math.random() * 256) # also in app/lib/auth
|
||||
user.set 'testGroupNumber', Math.floor(Math.random() * 256) # also in app/core/auth
|
||||
lang = languages.languageCodeFromAcceptedLanguages req.acceptedLanguages
|
||||
user.set 'preferredLanguage', lang if lang[...2] isnt 'en'
|
||||
user.set 'lastIP', req.connection.remoteAddress
|
||||
user.set 'chinaVersion', true if req.chinaVersion
|
||||
log.info "making new user #{user.get('_id')} with language #{user.get('preferredLanguage')} of #{req.acceptedLanguages} and chinaVersion #{req.chinaVersion} on #{if config.tokyo then 'Tokyo' else 'US'} server and lastIP #{req.connection.remoteAddress}."
|
||||
user
|
||||
|
|
|
@ -84,8 +84,11 @@ setupChinaRedirectMiddleware = (app) ->
|
|||
unless config.tokyo
|
||||
ip = req.headers['x-forwarded-for'] or req.connection.remoteAddress
|
||||
geo = geoip.lookup(ip)
|
||||
if speaksChinese or geo?.country is "CN"
|
||||
log.info("Should we redirect to Tokyo server? speaksChinese: #{speaksChinese}, acceptedLanguages: #{req.acceptedLanguages[0]}, ip: #{ip}, geo: #{geo} -- so redirecting? #{geo?.country is 'CN' and speaksChinese}")
|
||||
return geo?.country is "CN" and speaksChinese
|
||||
else
|
||||
log.info("We are on Tokyo server. speaksChinese: #{speaksChinese}, acceptedLanguages: #{req.acceptedLanguages[0]}")
|
||||
req.chinaVersion = true if speaksChinese
|
||||
return false # If the user is already redirected, don't redirect them!
|
||||
|
||||
|
|
Loading…
Reference in a new issue