Skip to content

Instantly share code, notes, and snippets.

@mgryszko
Created November 30, 2015 20:50
Show Gist options
  • Save mgryszko/ec2820ae73f97711867d to your computer and use it in GitHub Desktop.
Save mgryszko/ec2820ae73f97711867d to your computer and use it in GitHub Desktop.
Render conditionally JSON or JSONP in Dyson
function renderJsonp(res, callback) {
res.append('Content-Type', 'application/javascript');
res.send(callback + '(' + JSON.stringify(res.body) + ');');
}
function renderJson(res) {
res.send(res.body);
}
function render(req, res) {
var callback = req.query.callback;
if (callback) renderJsonp(res, callback);
else renderJson(res);
};
module.exports = {
path: '/api/v3/athlete/activities',
template: {
// ...
},
render: render
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment