mail beforeRender help!!!
-
Hello, how can I use the same script to bring different information to fill in each excel sheet?
function beforeRender(req, res, done) { req.options = req.options || {} req.options.preview = false require('request')({ url:"http://XX.XXX.XXX.XXX:8080/lib/jsonpa.php?tp=cartera1", json:true }, function(err, response, body){ console.log(JSON.stringify(body)) req.data = Object.assign({}, req.data, { cartera1: body }) done(); }); require('request')({ url:"http://XX.XXX.XXX.XXX:8080/lib/jsonpa.php?tp=cartera2", json:true }, function(err, response, body){ console.log(JSON.stringify(body)) req.data = Object.assign({}, req.data, { cartera2: body }) done(); }); return; }
o
function beforeRender(req, res, done) { req.options = req.options || {} req.options.preview = false require('request')({ url:"http://XX.XXX.XXX.XXX:8080/lib/jsonpa.php?tp=cartera1", json:true }, function(err, response, body){ console.log(JSON.stringify(body)) req.data = Object.assign({}, req.data, { cartera1: body }) done(); }); return; } function beforeRender2(req, res, done) { req.options = req.options || {} req.options.preview = false require('request')({ url:"http://XX.XXX.XXX.XXX:8080/lib/jsonpa.php?tp=cartera2", json:true }, function(err, response, body){ console.log(JSON.stringify(body)) req.data = Object.assign({}, req.data, { cartera2: body }) done(); }); return; }
-
So the problem is that you don't know how to fetch two URLs to get the input data?
This should be a common js implementation topic.
Here is how it can be wired to the jsreport script.const jsreport = require('jsreport-proxy') const axios = await jsreport.npm.require('axios@0.28.1') async function beforeRender(req, res) { const r = await axios.get('http://XX.XXX.XXX.XXX:8080/lib/jsonpa.php?tp=cartera1') req.data = { ...req.data, captera1: r.data } const r2 = await axios.get('http://XX.XXX.XXX.XXX:8080/lib/jsonpa.php?tp=cartera2') req.data = { ...req.data, captera2: ...r2.data} }