Created
May 19, 2017 15:45
-
-
Save gaboelnuevo/97fc882dbb6fc6d6df4555b4ab292577 to your computer and use it in GitHub Desktop.
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
var express = require('express'); | |
var app = express(); | |
var url = "https://username.jsreportonline.net/"; | |
var client = require("jsreport-client")(url, "[email protected]", "password"); | |
app.get('/', function (req, res) { | |
res.send('Go to /report or /base64'); | |
}); | |
app.get("/report", function(req, res, next) { | |
client.render({ | |
template: { "shortid": "HJ53LaK3x" }, | |
data: {} | |
}, function(err, response) { | |
if (err) { | |
return next(err); | |
} | |
response.pipe(res); | |
}); | |
}); | |
// Read this: (usage with promises) | |
// https://github.com/jsreport/nodejs-client/issues/1 | |
app.get("/base64", function(req, res, next) { | |
client.render({ | |
template: { "shortid": "HJ53LaK3x" }, | |
data: {} | |
}, function(err, response) { | |
if (err) { | |
return next(err); | |
} | |
response.body(function(reportBody) { | |
var report = reportBody.toString("base64"); | |
res.json({content: report, ContentType: "application/octet-stream"}) | |
}); | |
}); | |
}); | |
app.listen(3000, function () { | |
console.log('Example app listening on port 3000!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment