Skip to content

Instantly share code, notes, and snippets.

@drewfranz
Last active September 17, 2019 23:34
Show Gist options
  • Save drewfranz/bade11b0b03c992c67fd to your computer and use it in GitHub Desktop.
Save drewfranz/bade11b0b03c992c67fd to your computer and use it in GitHub Desktop.
/*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