From e43addf55b42fbc7237973ed355f75eae857d512 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Mon, 27 Jul 2015 11:35:20 -0700 Subject: [PATCH] Debugging chinaVersion inconsistencies. --- server/routes/auth.coffee | 4 +++- server_setup.coffee | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/routes/auth.coffee b/server/routes/auth.coffee index c672db0a9..094b39a02 100644 --- a/server/routes/auth.coffee +++ b/server/routes/auth.coffee @@ -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 diff --git a/server_setup.coffee b/server_setup.coffee index 5ac9e8c54..3174ea428 100644 --- a/server_setup.coffee +++ b/server_setup.coffee @@ -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!