Debugging chinaVersion inconsistencies.

This commit is contained in:
Nick Winter 2015-07-27 11:35:20 -07:00
parent 8cffb68462
commit e43addf55b
2 changed files with 6 additions and 1 deletions

View file

@ -7,6 +7,7 @@ config = require '../../server_config'
errors = require '../commons/errors' errors = require '../commons/errors'
languages = require '../routes/languages' languages = require '../routes/languages'
sendwithus = require '../sendwithus' sendwithus = require '../sendwithus'
log = require 'winston'
module.exports.setup = (app) -> module.exports.setup = (app) ->
authentication.serializeUser((user, done) -> done(null, user._id)) 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) -> module.exports.makeNewUser = makeNewUser = (req) ->
user = new User({anonymous: true}) 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 lang = languages.languageCodeFromAcceptedLanguages req.acceptedLanguages
user.set 'preferredLanguage', lang if lang[...2] isnt 'en' user.set 'preferredLanguage', lang if lang[...2] isnt 'en'
user.set 'lastIP', req.connection.remoteAddress user.set 'lastIP', req.connection.remoteAddress
user.set 'chinaVersion', true if req.chinaVersion 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 user

View file

@ -84,8 +84,11 @@ setupChinaRedirectMiddleware = (app) ->
unless config.tokyo unless config.tokyo
ip = req.headers['x-forwarded-for'] or req.connection.remoteAddress ip = req.headers['x-forwarded-for'] or req.connection.remoteAddress
geo = geoip.lookup(ip) 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 return geo?.country is "CN" and speaksChinese
else else
log.info("We are on Tokyo server. speaksChinese: #{speaksChinese}, acceptedLanguages: #{req.acceptedLanguages[0]}")
req.chinaVersion = true if speaksChinese req.chinaVersion = true if speaksChinese
return false # If the user is already redirected, don't redirect them! return false # If the user is already redirected, don't redirect them!