From e34158bcb5a0bb24688c91f1477c025811248264 Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Fri, 24 Nov 2023 20:59:37 +0300 Subject: [PATCH] updated the function, uses node-fetch now --- netlify/functions/handleMetadata.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index 55b5e45..1c7aaae 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -6,21 +6,11 @@ import { fetch } from 'node-fetch'; // Placeholder function to fetch content from URL using a web scraping service async function fetchContentFromURL(url) { - return new Promise((resolve, reject) => { - https.get(url, (response) => { - let data = ''; - // A chunk of data has been received. - response.on('data', (chunk) => { - data += chunk; - }); - // The whole response has been received. - response.on('end', () => { - resolve(data); - }); - }).on("error", (error) => { - reject(`Error fetching URL: ${error.message}`); - }); - }); + const response = await fetch(url); + if (!response.ok) { + throw new Error(`Error fetching URL: ${response.statusText}`); + } + return await response.text(); } function simplifyContent(content) {