From e622513893c8553c60b28b1403b1198229b3133a Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Tue, 28 May 2024 14:31:10 -0600 Subject: [PATCH 01/24] Update fetch.js this might not work..... Signed-off-by: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> --- netlify/functions/fetch/fetch.js | 38 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/netlify/functions/fetch/fetch.js b/netlify/functions/fetch/fetch.js index b60689d..dc32e85 100755 --- a/netlify/functions/fetch/fetch.js +++ b/netlify/functions/fetch/fetch.js @@ -20,18 +20,41 @@ exports.handler = async function (event, context) { boolean, }); - // Make the cURL request using axios + +exports.handler = async function (event, context) { + try { + // Parse the incoming form data from the request body + const { name, email, gdpr, hp, list, subform } = JSON.parse(event.body); + + // Construct the email data for Catapult Mailer + const data = { + personalizations: [ + { + to: [{ email: email }], // Use the email from the form submission as the recipient + subject: "New RSVP Submission", + }, + ], + from: { email: "team@purplebubble.org" }, // Replace with your sender email + content: [ + { + type: "text/plain", + value: `Name: ${name}\nEmail: ${email}\nGDPR: ${gdpr}\nHP: ${hp}\nList: ${list}\nSubform: ${subform}`, + }, + ], + }; + + // Make the request to Catapult Mailer using Cloudflare Email const response = await axios.post( - "https://postal.hackclub.com/subscribe", + "https://api.mailchannels.net/tx/v1/send", data, { headers: { - "Content-Type": "application/x-www-form-urlencoded", + "Content-Type": "application/json", }, - }, + } ); - // log the response for debugging purposes + // Log the response for debugging purposes console.log(response.data); // Return the response from the external API @@ -40,9 +63,10 @@ exports.handler = async function (event, context) { body: JSON.stringify(response.data), }; } catch (error) { - // Return an error response if something goes wrong - // log the error for debugging purposes + // Log the error for debugging purposes console.log(error); + + // Return an error response if something goes wrong return { statusCode: 500, body: JSON.stringify({ error: "Internal Server Error" }), From 5bc45882f7d94ff8cb7336136805d9d852ee72d1 Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Tue, 28 May 2024 17:41:00 -0600 Subject: [PATCH 02/24] Delete netlify/functions/fetch directory deleted Signed-off-by: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> --- netlify/functions/fetch/fetch.js | 75 -------------------------------- 1 file changed, 75 deletions(-) delete mode 100755 netlify/functions/fetch/fetch.js diff --git a/netlify/functions/fetch/fetch.js b/netlify/functions/fetch/fetch.js deleted file mode 100755 index dc32e85..0000000 --- a/netlify/functions/fetch/fetch.js +++ /dev/null @@ -1,75 +0,0 @@ -// fetch.js -const axios = require("axios"); -const qs = require("qs"); // Add this line - -exports.handler = async function (event, context) { - try { - // Parse the incoming form data from the request body - const { name, email, gdpr, hp, list, subform, boolean } = JSON.parse( - event.body, - ); - - // Stringify the data into a query string - const data = qs.stringify({ - name, - email, - gdpr, - hp, - list, - subform, - boolean, - }); - - -exports.handler = async function (event, context) { - try { - // Parse the incoming form data from the request body - const { name, email, gdpr, hp, list, subform } = JSON.parse(event.body); - - // Construct the email data for Catapult Mailer - const data = { - personalizations: [ - { - to: [{ email: email }], // Use the email from the form submission as the recipient - subject: "New RSVP Submission", - }, - ], - from: { email: "team@purplebubble.org" }, // Replace with your sender email - content: [ - { - type: "text/plain", - value: `Name: ${name}\nEmail: ${email}\nGDPR: ${gdpr}\nHP: ${hp}\nList: ${list}\nSubform: ${subform}`, - }, - ], - }; - - // Make the request to Catapult Mailer using Cloudflare Email - const response = await axios.post( - "https://api.mailchannels.net/tx/v1/send", - data, - { - headers: { - "Content-Type": "application/json", - }, - } - ); - - // Log the response for debugging purposes - console.log(response.data); - - // Return the response from the external API - return { - statusCode: response.status, - body: JSON.stringify(response.data), - }; - } catch (error) { - // Log the error for debugging purposes - console.log(error); - - // Return an error response if something goes wrong - return { - statusCode: 500, - body: JSON.stringify({ error: "Internal Server Error" }), - }; - } -}; From c6cd3b4d00f955e80a66f7d2719f583d74c441fc Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Tue, 28 May 2024 17:46:41 -0600 Subject: [PATCH 03/24] Update index.astro add the fetch functionality i think Signed-off-by: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> --- src/pages/index.astro | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/pages/index.astro b/src/pages/index.astro index 4cdc35f..339ac7d 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -93,3 +93,41 @@ import Layout from "../layouts/Layout.astro"; margin-right: 0.5rem; } + From eb18cb844048bbe9d81efbbc841533fa11a69f71 Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Tue, 28 May 2024 17:47:34 -0600 Subject: [PATCH 04/24] Delete netlify.toml Signed-off-by: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> --- netlify.toml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 netlify.toml diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index 2afbe24..0000000 --- a/netlify.toml +++ /dev/null @@ -1,11 +0,0 @@ -[dev] - command = "bun run dev" - -[build] - command = "bun run build" - publish = "dist" - -[[redirects]] - from = "/api/*" - to = "/.netlify/functions/:splat" - status = 200 \ No newline at end of file From 3db11de0f77f6900de476c99e72780686fd09472 Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Tue, 28 May 2024 17:51:30 -0600 Subject: [PATCH 05/24] Create netlify.toml Signed-off-by: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> --- netlify.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 netlify.toml diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..74d4177 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,11 @@ +[dev] + command = "bun run dev" + +[build] + command = "bun run build" + publish = "dist" + +[[redirects]] + from = "/api/*" + to = "/.netlify/functions/:splat" + status = 200 From 6b8e3250c909f968fff07dc1eb41a6354f55ac0d Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Wed, 29 May 2024 14:19:43 -0600 Subject: [PATCH 06/24] d --- .vscode/settings.json | 5 +++++ src/pages/index.astro | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a490b61 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] +} \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index 339ac7d..299e075 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -101,16 +101,17 @@ import Layout from "../layouts/Layout.astro"; const formData = new FormData(form); const data = { - name: formData.get('name'), email: formData.get('email'), - gdpr: formData.get('gdpr'), - hp: formData.get('hp'), - list: formData.get('list'), - subform: formData.get('subform') + name: formData.get('name'), + //gdpr: formData.get('gdpr'), + //hp: formData.get('hp'), + //list: formData.get('list'), + //subform: formData.get('subform') }; - + body: JSON.stringify({ email: 'example@gmail.com', name: 'Example User' }), + try { - const response = await fetch('https://catapult.purplebubble.org/dashboard', { + const response = await fetch('https://purplebubblewebsite.netlify.app/api/subscribe', { method: 'POST', headers: { 'Content-Type': 'application/json' From 9382e19162e72914dee1f6a706c498dd1d46b309 Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Wed, 29 May 2024 14:20:22 -0600 Subject: [PATCH 07/24] j --- src/pages/index.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index 299e075..7c7ec8a 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -102,13 +102,13 @@ import Layout from "../layouts/Layout.astro"; const data = { email: formData.get('email'), - name: formData.get('name'), + name: formData.get('name') //gdpr: formData.get('gdpr'), //hp: formData.get('hp'), //list: formData.get('list'), //subform: formData.get('subform') }; - body: JSON.stringify({ email: 'example@gmail.com', name: 'Example User' }), + //body: JSON.stringify({ email: 'example@gmail.com', name: 'Example User' }), try { const response = await fetch('https://purplebubblewebsite.netlify.app/api/subscribe', { From c990743d44d7677da96b1652134c0c234be51aed Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Wed, 29 May 2024 15:02:40 -0600 Subject: [PATCH 08/24] should work now --- src/pages/index.astro | 62 ++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index 7c7ec8a..3f64d8a 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,5 +1,28 @@ --- import Layout from "../layouts/Layout.astro"; +let error; +if (Astro.request.method === "POST") { + try { + const data = await Astro.request.formData(); + const name = data.get("name"); + const email = data.get("email”); + const response = await fetch('https://catapult.purplebubble.org/api/subscribe', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body = JSON.stringify({ name: name, email: email}) + }); + } + catch (error) { + if (error instanceof Error) { + { + error && ( +
Error: {error}
+ ) + } + } +} ---Error: {error}
+Error: {error}
) } } From 8582a5bae3ee903db6662c93e2349aa850f54626 Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Wed, 29 May 2024 15:24:52 -0600 Subject: [PATCH 12/24] h --- src/pages/index.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index d25a4c4..df77d6e 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -25,7 +25,7 @@ if (Astro.request.method === "POST") { if (error instanceof Error) { { error && ( -Error: {error}
+Error {error}
) } } From b35161a7f2ba1ede739478b11925b3462cafe4dc Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Wed, 29 May 2024 15:26:53 -0600 Subject: [PATCH 13/24] f --- src/pages/index.astro | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index df77d6e..7953d34 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -23,9 +23,8 @@ if (Astro.request.method === "POST") { } catch (error) { if (error instanceof Error) { - { error && ( -Error {error}
+Error: {error}
) } } From f768539104f81f67ab190f61f5d3204cd3836007 Mon Sep 17 00:00:00 2001 From: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com> Date: Wed, 29 May 2024 15:35:36 -0600 Subject: [PATCH 14/24] text --- src/pages/index.astro | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index 7953d34..54efb31 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,34 +1,37 @@ --- import Layout from "../layouts/Layout.astro"; -let error; + +let error = null; + if (Astro.request.method === "POST") { try { const data = await Astro.request.formData(); const name = data.get("name"); const email = data.get("email"); const response = await fetch('https://catapult.purplebubble.org/api/subscribe', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - } + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ name: name, email: email }) }); const jsondata = await response.json(); - if (jsondata.ok = true){ - //do nothing - }else{ + + if (!jsondata.ok) { error = jsondata.error; } - body = await request.body; - body = JSON.stringify({ name: name, email: email}) - } - catch (error) { - if (error instanceof Error) { - error && ( -Error: {error}
- ) + } catch (e) { + if (e instanceof Error) { + error = e.message; + } else { + error = "An unknown error occurred"; } } } +Error: {error}
} +Error: {error}
} ++ Error: {error} +
Error: {error}
Error: {error}
+ ) } } } --- -- Error: {error} -
-Error: {error}
- ) + console.log(error) } } } @@ -53,6 +51,9 @@ if (Astro.request.method === "POST") {Error: {error}
+ )}Error: {error}
- )} -