Last active
August 21, 2018 02:20
-
-
Save Na0ki/defb2bf50e360d65aad806f91033705f 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.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