node.js - 生产中的 Puppeteer 504 网关超时错误
问题描述
我已经使用 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);
},
};
当我在 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。
谁能帮我解决这个问题。
解决方案
推荐阅读
- r - 将字符串提取到每行中的不同单词 - R
- reactjs - Apollo Client React:如何将从查询中获得的数据作为参数传递给graphql中的另一个查询?
- c# - 如何根据 c# 中的以下分组产品类别显示我的回复
- perl - Perl 评估范围
- python - 如何使用 Pydantic 验证器验证条目?
- oracle - 是否可以在本地 Oracle 数据库中启用自治数据库的 DBMS_CLOUD pls/sql 包?
- c++ - Ubuntu 18.04 上的 GCC > 7,预计可以工作吗?
- r - 如何让 confint.segmented 为 R 中的任何数据集工作?
- typescript - 无论我尝试什么,打字稿对象都可能未定义
- excel - 选择A列中的最后一个非空单元格->根据C列中的最后一个非空单元格填写A列下方的空单元格->重复