Skip to content

Instantly share code, notes, and snippets.

@tunchamroeun
Created October 25, 2020 18:30
Show Gist options
  • Select an option

  • Save tunchamroeun/6b2c064321df07f86a12e662dadf05d2 to your computer and use it in GitHub Desktop.

Select an option

Save tunchamroeun/6b2c064321df07f86a12e662dadf05d2 to your computer and use it in GitHub Desktop.
fastify.post("/render-docx", (req, reply) => {
const client = require("jsreport-client")("http://localhost:5488", "cloudware", "cloudware@jsreport")
client.render({
template: {name: req.body.template},
data:JSON.stringify(req.body.data),
}).then(async function (response) {
const file_path = 'public/report.docx'
if (fs.existsSync(file_path)){
fs.unlinkSync(file_path)
}
fs.writeFileSync('public/report.docx', await response.body())
/*reply.code(200)
reply.type('application/docx');
reply.header('Content-disposition', 'attachment; filename=' + moment(new Date()).format('DD-MM-YYYY-h-m-s')+'-report.docx');*/
// reply.send(await response.body())
reply.send({report_url:'https://phk1-word-view.officeapps.live.com/wv/WordViewer/request.pdf?WOPIsrc=http://188.166.189.3:4000/report.docx'})
})
});
fastify.get("/backup", (req, reply) => {
backup({
uri: 'mongodb://mongo:27017/school-management',
root: __dirname,
tar: 'school-management.tar',
callback: function(err) {
if (err) {
reply.send({success:false,message:'Error Downloading'})
} else {
reply.code(200)
reply.type('application/x-tar');
reply.header('Content-disposition', 'attachment; filename=' + moment(new Date()).format('DD-MM-YYYY-h-m-s')+'-school-management.tar');
const stream = fs.createReadStream('school-management.tar')
reply.send(stream)
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment