Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Update fetch.js this might not work.....
Browse files Browse the repository at this point in the history
Signed-off-by: Emperor Numerius <[email protected]>
  • Loading branch information
EmperorNumerius authored May 28, 2024
1 parent ffdfd7e commit e622513
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions netlify/functions/fetch/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]" }, // 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
Expand All @@ -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" }),
Expand Down

0 comments on commit e622513

Please sign in to comment.