diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index de23e16..6dd08c8 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -1,13 +1,24 @@ -const fetch = require('node-fetch'); // Import for webscraping (fetchContentFromURL(url) function -// const https = require('https'); +const https = require('https'); // Import for webscraping (fetchContentFromURL(url) function // Placeholder function to fetch content from URL using a web scraping service async function fetchContentFromURL(url) { - // Implement logic to fetch content from the URL using a web scraping service - // Return the extracted content - // Placeholder code - const content = "
This is a sample content fetched from the URL
"; - return content; + 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}`); + }); + }); } // Placeholder function to simplify the content for GPT analysis