在部署到Vercel后,在我的某个页面上出现了此错误,在开发模式下一切正常。
我认为问题可能是我的一个fetch / API之一,因为它使用第一个fetch请求的数据作为第二个fetch请求的URL...
我所有其他使用不同API / fetch请求的页面都能正常工作...
export const fetchData = async (page) => {
try {
const req = await fetch(
"https://www.productpage.com/new/" +
page
);
const html = await req.text();
const $ = cheerio.load(html);
let newProducts = [];
for (let i = 1; i < 25; i++) {
let name = $(`#product_listing > tbody > #_${i} > td:nth-child(2) > a`)
.text()
.replace(/\n/g, "");
let pageSrc = $(
`#product_listing > tbody > #_${i} > td:nth-child(2) > a`
).attr("href");
const price = $(`#product_listing > tbody >#_${i} > td.price.notranslate`)
.text()
.replace(/\n/g, "");
pageSrc = "https://www.productpage.com" + pageSrc;
const req2 = await fetch(pageSrc); // here it is using data from first fetch for a 2nd request..
const html2 = await req2.text();
const $2 = cheerio.load(html2);
const imageSrc = $2(
"#product-main-image .main-image-inner:first-child img"
).attr("src");
const name2 = $2("#product-details dd:nth-child(2)")
.text()
.replace(/\n/g, "");
const brand = $2("#product-details dd:nth-child(4)")
.text()
.replace(/\n/g, "");
newProducts.push({
name: name,
name2: name2,
brand: brand,
pageSrc: pageSrc,
price: price,
imageSrc: imageSrc,
});
}
return newProducts;
} catch (err) {}
};
module.exports = {
fetchData,
};
sudo ufw allow 3306/tcp
。唯一的原因是因为我已经将该IP地址添加到了允许列表中,所以连接从我的家庭办公室可以正常工作。 - Ryan