Last active
September 17, 2019 23:34
-
-
Save drewfranz/bade11b0b03c992c67fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint maxlen: 3000*/ | |
var Chaps = require('chaps'), | |
//config = require('rind').config, | |
chaps = new Chaps({ | |
//hostname : config.app.api.host, | |
hostname : 'https://api.example.com', // TODO: temporary get prod data | |
timeout : 3000 | |
}); | |
function apiGet (url, cb) { | |
chaps.get({ | |
url : url, | |
}, function (err, res) { | |
var body = (res || {}).body || {}; | |
if (err) { | |
cb(err); | |
} else if (body.error) { | |
cb(new Error(body.message || body.error)); | |
} else { | |
cb(null, body); | |
} | |
}); | |
} | |
function getCourseData (req, res, slug, cb) { | |
apiGet('/courses/' + slug, function(err, data) { | |
data = data || {}; | |
cb(err, data); | |
}); | |
} | |
function getLiveData (req, res, liveId, cb) { | |
apiGet('/channel/live' + liveId, function (err, data) { | |
data = data || {}; | |
data.course = data.course || {}; | |
data.course.social = null; | |
cb(err, data); | |
}); | |
} | |
function clone (data) { | |
var copy = {}; | |
Object.keys(data).forEach(function (key) { | |
copy[key] = data[key]; | |
}); | |
return copy; | |
} | |
exports.routes = function (app) { | |
app.get('/liveapp/:id?', function (req, res, next) { | |
var liveId = req.params.id || 1; | |
getLiveData(req, res, liveId, function (err, results) { | |
if (err) { return next(err); } | |
var resultsnew = results; | |
var data = null; | |
getCourseData(req, res, results.course.slug, function(err, course) { | |
resultsnew.course = course || {}; | |
data = clone(results); | |
data.dump = results; | |
data.hideUpstairs = true; | |
res.render('objects/channel/live/main', data); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment