From 7f0c6faa03b72ad02a56f286368f2991f7c0b58e Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:53:15 +0800 Subject: [PATCH 01/20] Update hello.js --- netlify/functions/hello.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index 0c8df43..50a8b31 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -5,11 +5,12 @@ // You can develop and deploy serverless functions right here as part // of your site. Netlify Functions will handle the rest for you. - +const axios = require('axios'); exports.handler = async event => { + const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665'); const subject = event.queryStringParameters.name || 'World' return { statusCode: 200, - body: `Hello ${subject}!`, + body: `Hello ${subject}! ${response.data}`, } -} \ No newline at end of file +} From 75b9882cc1bafa4869fd8c8a37e7351d29a402ad Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:00:51 +0800 Subject: [PATCH 02/20] Update netlify.toml --- netlify.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/netlify.toml b/netlify.toml index fbb70bd..3c501a0 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,7 @@ [build] publish = "public" command = "echo No build command" + functions = "functions" node_bundler = "esbuild" [dev] From b36fcd4bc1ffee13d4282ba6e7dd758bd550b3d8 Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:04:36 +0800 Subject: [PATCH 03/20] Update hello.js --- netlify/functions/hello.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index 50a8b31..2677585 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -5,12 +5,12 @@ // You can develop and deploy serverless functions right here as part // of your site. Netlify Functions will handle the rest for you. -const axios = require('axios'); +//const axios = require('axios'); exports.handler = async event => { - const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665'); + //const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665'); const subject = event.queryStringParameters.name || 'World' return { statusCode: 200, - body: `Hello ${subject}! ${response.data}`, + body: `Hello ${subject}! `, } } From 578c0970e98e1ab094c7c68a379fef82284e18da Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:06:49 +0800 Subject: [PATCH 04/20] Update netlify.toml --- netlify.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index 3c501a0..fbb70bd 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,6 @@ [build] publish = "public" command = "echo No build command" - functions = "functions" node_bundler = "esbuild" [dev] From b29a1bacedc4f2e0a1e1f7a5989d7643f4e6e8cc Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:15:58 +0800 Subject: [PATCH 05/20] Update netlify.toml --- netlify.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/netlify.toml b/netlify.toml index fbb70bd..8c12003 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,7 @@ [build] publish = "public" command = "echo No build command" + functions = "build/functions" node_bundler = "esbuild" [dev] From e88b317e0de59d6c9766039a2114775baaa9837d Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:20:40 +0800 Subject: [PATCH 06/20] Update netlify.toml --- netlify.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netlify.toml b/netlify.toml index 8c12003..ff12c90 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,7 @@ [build] publish = "public" - command = "echo No build command" - functions = "build/functions" + command = "npm run build" + functions = "functions/" node_bundler = "esbuild" [dev] From 9b08a9994fbd9d27f10ea5337e4a6445f5eceedb Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:26:12 +0800 Subject: [PATCH 07/20] Update netlify.toml --- netlify.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index ff12c90..18c7b06 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,7 @@ [build] publish = "public" command = "npm run build" - functions = "functions/" + functions = "netlify/functions/" node_bundler = "esbuild" [dev] From 955c43cfa533251f8ba121f7955c70a71972a5b7 Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:30:10 +0800 Subject: [PATCH 08/20] Update package.json --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index badedc7..bc2ffb7 100644 --- a/package.json +++ b/package.json @@ -4,4 +4,8 @@ "description": "A site to show a hello world example of using Netlify Functions", "author": "Netlify", "license": "ISC" -} \ No newline at end of file + "dependencies": { + + "axios": "^1.4.0" + }, +} From 597147a8bf003d21fee0343a6cf9adc7f0814cde Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:30:58 +0800 Subject: [PATCH 09/20] Update netlify.toml --- netlify.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index 18c7b06..5f539f1 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,6 @@ [build] publish = "public" - command = "npm run build" + functions = "netlify/functions/" node_bundler = "esbuild" From 48b1e8a7b75054a51b23a6d0a0853d5123b9791c Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:32:21 +0800 Subject: [PATCH 10/20] Update package.json --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bc2ffb7..c9fb5fd 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,8 @@ "version": "1.0.0", "description": "A site to show a hello world example of using Netlify Functions", "author": "Netlify", - "license": "ISC" + "license": "ISC", "dependencies": { - "axios": "^1.4.0" - }, + } } From a16f7ed8bf053f990e75e461bafb57fcf35f7e00 Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:33:49 +0800 Subject: [PATCH 11/20] Update hello.js --- netlify/functions/hello.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index 2677585..d152464 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -7,10 +7,10 @@ //const axios = require('axios'); exports.handler = async event => { - //const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665'); + const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665'); const subject = event.queryStringParameters.name || 'World' return { statusCode: 200, - body: `Hello ${subject}! `, + body: `Hello ${subject}! ${response.data} `, } } From 13a0dbabc38aee37c73f3683f802da1d834ca235 Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:34:46 +0800 Subject: [PATCH 12/20] Update hello.js --- netlify/functions/hello.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index d152464..b3b29b1 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -5,7 +5,7 @@ // You can develop and deploy serverless functions right here as part // of your site. Netlify Functions will handle the rest for you. -//const axios = require('axios'); +const axios = require('axios'); exports.handler = async event => { const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665'); const subject = event.queryStringParameters.name || 'World' From eced6ec92b2fa5b3ab1e1744f793c6f04fa234e4 Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:39:25 +0800 Subject: [PATCH 13/20] Update hello.js --- netlify/functions/hello.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index b3b29b1..c78b099 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -7,7 +7,7 @@ const axios = require('axios'); exports.handler = async event => { - const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665'); + const response = await axios.get('https://www.learnwithjason.dev/blog/serverless-functions/deploy-first-serverless-function/'); const subject = event.queryStringParameters.name || 'World' return { statusCode: 200, From f6a883bfdd57c33a1ad31fb7076b619ba4b7975a Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:42:32 +0800 Subject: [PATCH 14/20] Update hello.js --- netlify/functions/hello.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index c78b099..37fbf76 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -7,7 +7,7 @@ const axios = require('axios'); exports.handler = async event => { - const response = await axios.get('https://www.learnwithjason.dev/blog/serverless-functions/deploy-first-serverless-function/'); + const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665/'); const subject = event.queryStringParameters.name || 'World' return { statusCode: 200, From a037c1a0847497f1e6a08c2e4ec049e270092cda Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:07:10 +0800 Subject: [PATCH 15/20] Update hello.js --- netlify/functions/hello.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index 37fbf76..a346532 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -14,3 +14,20 @@ exports.handler = async event => { body: `Hello ${subject}! ${response.data} `, } } + + +function getDataUrl(url) { + return axios + .get(url, { + responseType: 'arraybuffer', + }) + .then((response) => { + const contentType = response.headers['content-type']; + const base64 = Buffer.from(response.data, 'binary').toString('base64'); + return `data:${contentType};base64,${base64}`; + }) + .catch((error) => { + console.error('Error fetching image:', error.message); + return url; // Return the original URL on error + }); +} From 35d6b25e80d9e792f165d85101b36e01bdf32d7c Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:07:57 +0800 Subject: [PATCH 16/20] Update hello.js --- netlify/functions/hello.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index a346532..55b7369 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -7,7 +7,7 @@ const axios = require('axios'); exports.handler = async event => { - const response = await axios.get('https://ithelp.ithome.com.tw/articles/10315665/'); + const response = await axios.get('https://css-tricks.com/accessing-data-netlify-functions-react/'); const subject = event.queryStringParameters.name || 'World' return { statusCode: 200, From 11eca2e41653de4309088ec4d198573ba4ed6742 Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:09:50 +0800 Subject: [PATCH 17/20] Update hello.js --- netlify/functions/hello.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index 55b7369..15c19cd 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -7,6 +7,8 @@ const axios = require('axios'); exports.handler = async event => { + + /* const response = await axios.get('https://css-tricks.com/accessing-data-netlify-functions-react/'); const subject = event.queryStringParameters.name || 'World' return { @@ -14,6 +16,33 @@ exports.handler = async event => { body: `Hello ${subject}! ${response.data} `, } } +*/ + try { + const response = await axios.get(url); + const { document } = new JSDOM(response.data).window; + + const images = document.querySelectorAll('img'); + + images.forEach((img) => { + const dataUrl = getDataUrl(img.src); + img.src = dataUrl; + }); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'text/html', + }, + body: document.documentElement.outerHTML, + }; + } catch (error) { + console.error('Error:', error.message); + return { + statusCode: 500, + body: 'An error occurred while rendering the page.', + }; + } +}; function getDataUrl(url) { From ac10ab0d1b6449d32433fa717ec22887507ef7ad Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:10:40 +0800 Subject: [PATCH 18/20] Update hello.js --- netlify/functions/hello.js | 1 + 1 file changed, 1 insertion(+) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index 15c19cd..5f46a61 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -6,6 +6,7 @@ // of your site. Netlify Functions will handle the rest for you. const axios = require('axios'); +const { JSDOM } = require('jsdom'); exports.handler = async event => { /* From facfd085380eeeb46b78cbea8ab45bebdb9b5169 Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:11:12 +0800 Subject: [PATCH 19/20] Update package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c9fb5fd..28d9c26 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "author": "Netlify", "license": "ISC", "dependencies": { - "axios": "^1.4.0" + "axios": "^1.4.0", + "jsdom": "^24.0.0" } } From f1ed1c6012ff039c726caede38d42d0d4275557b Mon Sep 17 00:00:00 2001 From: Otelia Cronin <67236396+ccsourcecode@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:32:15 +0800 Subject: [PATCH 20/20] Update hello.js --- netlify/functions/hello.js | 1 + 1 file changed, 1 insertion(+) diff --git a/netlify/functions/hello.js b/netlify/functions/hello.js index 5f46a61..3250ad9 100644 --- a/netlify/functions/hello.js +++ b/netlify/functions/hello.js @@ -18,6 +18,7 @@ exports.handler = async event => { } } */ + const url = "https://css-tricks.com/accessing-data-netlify-functions-react/"; try { const response = await axios.get(url); const { document } = new JSDOM(response.data).window;