mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 10:56:53 -05:00
Deferring user creation until after the client app loads, to try and lower the massive number of anonymous users that are created.
This commit is contained in:
parent
fb29bfa71e
commit
ba1ffe194c
2 changed files with 19 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
||||||
Backbone.Mediator.setValidationEnabled false
|
Backbone.Mediator.setValidationEnabled false
|
||||||
app = require 'core/application'
|
app = null
|
||||||
|
|
||||||
channelSchemas =
|
channelSchemas =
|
||||||
'auth': require 'schemas/subscriptions/auth'
|
'auth': require 'schemas/subscriptions/auth'
|
||||||
|
@ -21,6 +21,15 @@ definitionSchemas =
|
||||||
'misc': require 'schemas/definitions/misc'
|
'misc': require 'schemas/definitions/misc'
|
||||||
|
|
||||||
init = ->
|
init = ->
|
||||||
|
return if app
|
||||||
|
if not window.userObject._id
|
||||||
|
$.ajax('/auth/whoami', {success: (res) ->
|
||||||
|
window.userObject = res
|
||||||
|
init()
|
||||||
|
})
|
||||||
|
return
|
||||||
|
|
||||||
|
app = require 'core/application'
|
||||||
setupConsoleLogging()
|
setupConsoleLogging()
|
||||||
watchForErrors()
|
watchForErrors()
|
||||||
setUpIOSLogging()
|
setUpIOSLogging()
|
||||||
|
@ -34,8 +43,6 @@ init = ->
|
||||||
handleNormalUrls()
|
handleNormalUrls()
|
||||||
setUpMoment() # Set up i18n for moment
|
setUpMoment() # Set up i18n for moment
|
||||||
|
|
||||||
module.exports.init = init = _.once init
|
|
||||||
|
|
||||||
handleNormalUrls = ->
|
handleNormalUrls = ->
|
||||||
# http://artsy.github.com/blog/2012/06/25/replacing-hashbang-routes-with-pushstate/
|
# http://artsy.github.com/blog/2012/06/25/replacing-hashbang-routes-with-pushstate/
|
||||||
$(document).on 'click', "a[href^='/']", (event) ->
|
$(document).on 'click', "a[href^='/']", (event) ->
|
||||||
|
|
|
@ -127,26 +127,15 @@ setupJavascript404s = (app) ->
|
||||||
|
|
||||||
setupFallbackRouteToIndex = (app) ->
|
setupFallbackRouteToIndex = (app) ->
|
||||||
app.all '*', (req, res) ->
|
app.all '*', (req, res) ->
|
||||||
if req.user
|
fs.readFile path.join(__dirname, 'public', 'main.html'), 'utf8', (err, data) ->
|
||||||
sendMain(req, res)
|
log.error "Error modifying main.html: #{err}" if err
|
||||||
# Disabling for HoC
|
# insert the user object directly into the html so the application can have it immediately. Sanitize </script>
|
||||||
# req.user.set('lastIP', req.connection.remoteAddress)
|
user = if req.user then JSON.stringify(UserHandler.formatEntity(req, req.user)).replace(/\//g, '\\/') else '{}'
|
||||||
# req.user.save()
|
data = data.replace('"userObjectTag"', user)
|
||||||
else
|
res.header 'Cache-Control', 'no-cache, no-store, must-revalidate'
|
||||||
user = auth.makeNewUser(req)
|
res.header 'Pragma', 'no-cache'
|
||||||
makeNext = (req, res) -> -> sendMain(req, res)
|
res.header 'Expires', 0
|
||||||
next = makeNext(req, res)
|
res.send 200, data
|
||||||
auth.loginUser(req, res, user, false, next)
|
|
||||||
|
|
||||||
sendMain = (req, res) ->
|
|
||||||
fs.readFile path.join(__dirname, 'public', 'main.html'), 'utf8', (err, data) ->
|
|
||||||
log.error "Error modifying main.html: #{err}" if err
|
|
||||||
# insert the user object directly into the html so the application can have it immediately. Sanitize </script>
|
|
||||||
data = data.replace('"userObjectTag"', JSON.stringify(UserHandler.formatEntity(req, req.user)).replace(/\//g, '\\/'))
|
|
||||||
res.header 'Cache-Control', 'no-cache, no-store, must-revalidate'
|
|
||||||
res.header 'Pragma', 'no-cache'
|
|
||||||
res.header 'Expires', 0
|
|
||||||
res.send 200, data
|
|
||||||
|
|
||||||
setupFacebookCrossDomainCommunicationRoute = (app) ->
|
setupFacebookCrossDomainCommunicationRoute = (app) ->
|
||||||
app.get '/channel.html', (req, res) ->
|
app.get '/channel.html', (req, res) ->
|
||||||
|
|
Loading…
Reference in a new issue