Created
November 30, 2015 20:50
-
-
Save mgryszko/ec2820ae73f97711867d to your computer and use it in GitHub Desktop.
Render conditionally JSON or JSONP in Dyson
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
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