});
worker.on('message', resolve);
worker.on('error', reject);
worker.on('exit', (code) => {
if (code !== 0) {
reject(new Error(`Worker stopped with exit code ${code}`));
}
worker.terminate()
});
});
return workerResult
};
transform.middleware = function(req, res, next) {
res.xls = async (filename, data, options) => {
try {
options = options || {}
options.output = 'binary';
options = ensureOptions(options)
const xls = await transform(data, options);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
res.end(xls, 'binary');
} catch(e) {
res.status(500).send({
status: 'error',
ok: false,
message: e.message
})