-
-
Save giladno/952b1fe847de8f66fdc1a90b8536bb3e 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
app.get('/pdf', authenticated, async (req, res)=>{ | |
let browser = await puppeteer.launch(); | |
try { | |
let page = await browser.newPage(); | |
await page.goto(url.format({ | |
protocol: 'http:', | |
host: '127.0.0.1:3000', | |
pathname: '/', | |
query: req.query, | |
}), {waitUntil: 'networkidle'}); | |
await page.evaluate(()=>new Promise(resolve=>{ | |
if (window.tn_onload) | |
return resolve(); | |
window.tn_onload = resolve; | |
setTimeout(resolve, 30000); | |
})); | |
let pdf = await page.pdf({format: 'A4'}); | |
res.writeHead(200, { | |
'Content-Type': 'application/pdf', | |
'Content-Disposition': 'attachment; filename=claim.pdf', | |
'Content-Length': pdf.length, | |
}); | |
res.end(pdf); | |
} finally { browser.close(); } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment