Skip to content

Commit dcf57dc

Browse files
committed
Merge pull request #62 from RandomAPI/jsonp#61
Added JSONP support#61
2 parents d90130b + ee6984b commit dcf57dc

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

routes/api.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ function genUser(req, res, version) {
5050
new Generator[version](req.query).generate((output, ext) => {
5151
var name = "tmp/" + String(new Date().getTime());
5252

53+
if (typeof req.query.callback !== 'undefined' && ext === "json") {
54+
output = String(req.query.callback) + "(" + output + ");";
55+
}
56+
5357
// Download - save file and update headers
5458
if (dl) {
5559
res.setHeader('Content-disposition', 'attachment; filename=download.' + ext);
@@ -83,13 +87,13 @@ function genUser(req, res, version) {
8387
output = JSON.parse(output);
8488
var extObj = {
8589
results: [{
86-
user: {
87-
picture: output.results[0].picture.large.replace('/api', ''),
88-
name: {
89-
first: output.results[0].name.first,
90-
last: output.results[0].name.last
91-
}
90+
user: {
91+
picture: output.results[0].picture.large.replace('/api', ''),
92+
name: {
93+
first: output.results[0].name.first,
94+
last: output.results[0].name.last
9295
}
96+
}
9397
}]
9498
};
9599
res.send(extObj);

0 commit comments

Comments
 (0)