【发布时间】:2021-04-27 13:47:35
【问题描述】:
我正在我的 NodeJs 服务器上使用 puppeteer、cheerio 和 pdfkit 创建网站的 pdf,这需要花费大量时间,现在我想在客户端取消请求(即关闭浏览器、选项卡等)时中止所有进程,以便服务器不会处理不必要的过程。 例如:
app.get("/api/processScreenshot/:url", async (req, resp) => {
const links = await collectAllLinks(url);
const screenshotsPath = await takeScreenshots(links);
const pdfPath = await createPDF(screenshotsPath);
resp.status(200).end(pdfPath);
});
如果请求以任何方式取消,即它收到 cancel、close 或 abort 事件?
【问题讨论】: