我有一个循环,它对一个GET url进行了19次调用。
generateMonthlyPNG(recap) {
for (const meter of meters) { // 19 elements
let url = process.env.BASE_URL + "operations/" + recap.operation.name + "/meters/" + meter + "/monthly";
promises.push(this.makePngScreenshot(recap, url, meter, "monthly"));
}
return promises
}通过以下方式:
async makePngScreenshot(recap, url, meterId, filename) {
axios.get(url, null); // Make the request to generate html page
const destination = "public/images/" + recap.operation.name + "/" + recap.date_ini + "_" + recap.date_end + "/" + meterId
// console.log("Creating image in: " + destination)
return new Pageres({ delay: 2, filename: filename })
.src(url, ['1300x650'], { crop: true })
.dest(destination)
.run()
}
app.get("/operations/:operation/meters/:meter/monthly", async (req, res) => { // Used to generate PNG from graph
console.log(".")
}generateMonthlyPNG只调用一次
奇怪的是,我有19米,我打印38个点(.),所以,我重复我的所有呼叫,我不知道为什么。
有什么想法吗?
发布于 2021-10-14 15:25:50
您似乎正在访问该URL两次,一次是使用:
axios.get(url)再说一遍:
new Pageres({ delay: 2, filename: filename })
.src(url, ['1300x650'], { crop: true })
.dest(destination)
.run()这将导致底层代码请求同一页面两次。
https://stackoverflow.com/questions/69571526
复制相似问题