18 lines
592 B
JavaScript
18 lines
592 B
JavaScript
|
const Report = require('vn-print/core/report');
|
||
|
|
||
|
module.exports = async function(request, response, next) {
|
||
|
try {
|
||
|
const reportName = request.params.name;
|
||
|
const args = response.locals;
|
||
|
const report = new Report(reportName, args);
|
||
|
const stream = await report.toPdfStream();
|
||
|
const fileName = await report.getFileName();
|
||
|
|
||
|
response.setHeader('Content-type', 'application/pdf');
|
||
|
response.setHeader('Content-Disposition', `inline; filename="${fileName}"`);
|
||
|
response.end(stream);
|
||
|
} catch (error) {
|
||
|
next(error);
|
||
|
}
|
||
|
};
|