Skip to content

Instantly share code, notes, and snippets.

@sohalloran
Last active December 12, 2015 05:28
Show Gist options
  • Save sohalloran/4722069 to your computer and use it in GitHub Desktop.
Save sohalloran/4722069 to your computer and use it in GitHub Desktop.
JSONPify Example - Example of adding JSONP support to a REST API via a proxy node.js service
// Client JS
$.ajax({
cache: false,
dataType: 'jsonp',
url: 'https://MY_JSONP_SERVER/jsonp?sid='+SID_HERE+'&path='+REST_RESOURCE,
success: function(data){
console.log(JSON.stringify(data));
}
});
// Server JS
var jsonpHandler = function(req, res){
var sid = req.query["sid"];
var path = req.query["path"];
rest.get(path ,{
headers: {
'Accept':'application/json',
'Authorization': 'OAuth ' + sid,
'Content-Type': 'application/json',
}
}).on('complete', function(result) {
res.type('application/json');
res.jsonp(result);
res.end();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment