mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Add healthcheck route
This commit is contained in:
parent
187a6f87a9
commit
0fe700b6bf
1 changed files with 35 additions and 1 deletions
|
@ -1,2 +1,36 @@
|
|||
module.exports.setup = (app) ->
|
||||
app.get('/db/products', require('./db/product').get)
|
||||
app.get '/db/products', require('./db/product').get
|
||||
|
||||
app.get '/healthcheck', (req, res) ->
|
||||
try
|
||||
async = require 'async'
|
||||
User = require '../users/User'
|
||||
async.waterfall [
|
||||
(callback) ->
|
||||
User.find({}).limit(1).exec(callback)
|
||||
, (last, callback) ->
|
||||
return("No users found") unless callback.length > 0
|
||||
User.findOne(slug: 'healthcheck').exec(callback)
|
||||
, (hcuser, callback) ->
|
||||
# Create health check user if it doesnt exist
|
||||
return callback(null, hcuser) if hcuser
|
||||
user = new User
|
||||
anonymous: false
|
||||
name: 'healthcheck'
|
||||
nameLower: 'healthcheck'
|
||||
slug: 'healthcheck'
|
||||
email: 'rob+healthcheck@codecombat.com'
|
||||
emailLower: 'rob+healthcheck@codecombat.com'
|
||||
user.set 'testGroupNumber', Math.floor(Math.random() * 256) # also in app/core/auth
|
||||
user.save (err) ->
|
||||
return callback(err) if err
|
||||
callback(null, user)
|
||||
|
||||
, (hcuser, callback) ->
|
||||
activity = hcuser.trackActivity 'healthcheck', 1
|
||||
hcuser.update {activity: activity}, callback
|
||||
], (err) ->
|
||||
return res.status(500).send(err.toString()) if err
|
||||
res.send("OK")
|
||||
catch error
|
||||
res.status(500).send(error.toString())
|
||||
|
|
Loading…
Reference in a new issue