This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update fetch.js this might not work.....
Signed-off-by: Emperor Numerius <[email protected]>
- Loading branch information
1 parent
ffdfd7e
commit e622513
Showing
1 changed file
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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" }), | ||
|