[英]Puppeteer 504 Gateway Time-out error in production
I have implemented pdf generation using puppeteer我已经使用 puppeteer 实现了 pdf 生成
const puppeteer = require("puppeteer");
module.exports = {
async generate(req, res) {
let url = req.query.url;
let name = req.query.name ? req.query.name : "file";
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
const page = await browser.newPage();
await page.goto(url, { waitUntil: "networkidle0" });
const pdf = await page.pdf({ format: "A4" });
await browser.close();
res.set({
"Content-Type": "application/pdf",
"Content-Length": pdf.length,
});
res.setHeader("Content-disposition", `attachment; filename=${name}.pdf`);
res.send(pdf);
},
};
The above code is running fine when I try this in localhost and it generates the PDF but when I am moving this to production then it keeps loading and gives 504 Gateway error ex: https://api.socialtools.me/core/html-to-pdf?url=https://apps.socialtools.me/preview/discount-coupon/613e0c6a9115bb003681958d/print/0&name=discount-coupon .当我在 localhost 中尝试此操作并生成 PDF 时,上面的代码运行良好,但是当我将其移至生产环境时,它会继续加载并给出 504 网关错误,例如: https ://api.socialtools.me/core/html- to-pdf?url=https://apps.socialtools.me/preview/discount-coupon/613e0c6a9115bb003681958d/print/0&name=discount-coupon 。
Can anyone, please help me to solve this issue.谁能帮我解决这个问题。
For me on Linux, the only way to resolve is by installing some dependencies:对于 Linux 上的我来说,解决的唯一方法是安装一些依赖项:
sudo apt-get update
sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
sudo apt-get install -y libgbm-dev
reference:参考:
https://github.com/puppeteer/puppeteer/issues/5662?fbclid=IwAR17HxYebtc14UvptAAUUk7qd4oMTysm-Uasv7KBm1LN7aN2H7GAkj6IxIU#issuecomment-732076246 https://github.com/puppeteer/puppeteer/issues/5662?fbclid=IwAR17HxYebtc14UvptAAUUk7qd4oMTysm-Uasv7KBm1LN7aN2H7GAkj6IxIU#issuecomment-732076246
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.