Skip to content

Instantly share code, notes, and snippets.

@Na0ki
Last active August 21, 2018 02:20
Show Gist options
  • Save Na0ki/defb2bf50e360d65aad806f91033705f to your computer and use it in GitHub Desktop.
Save Na0ki/defb2bf50e360d65aad806f91033705f to your computer and use it in GitHub Desktop.
app.post('/', async (req, res) => {
const html = req.body.html;
if (!html) {
await res.status(400);
return;
}
try {
await page.goto(
`data:text/html,${html}`, {
timeout: pageTimeoutMsec,
waitUntil: ["load", "domcontentloaded", "networkidle0"]
}
);
await page.setCacheEnabled(false);
await page.reload({waitUntil: 'networkidle2'});
const buff = await page.pdf(option);
await res.status(200).contentType("application/pdf").send(buff).end();
} catch (e) {
console.error(e);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment