Quiz-PDF/Frontend/netlify/functions/triggerSignUpEmail/index.ts

64 lines
1.9 KiB
TypeScript

exports.handler = async function (event: Event) {
console.log(event);
return {
statusCode: 200,
body: "Hello, World!",
headers: {
"Access-Control-Allow-Origin": "http://localhost:3000", // <-- This allows any domain
// "Access-Control-Allow-Headers": "Content-Type",
},
};
};
// import fetch from 'node-fetch-commonjs';
// export async function handler(event) {
// if (event.body === null) {
// return {
// statusCode: 400,
// body: JSON.stringify("Payload required"),
// headers: {
// "Access-Control-Allow-Origin": "*",
// "Access-Control-Allow-Headers": "Content-Type"
// }
// };
// }
// console.log("Incoming event.body:", event.body);
// const requestBody = JSON.parse(event.body);
// if(!requestBody){
// console.log("No Body")
// }
// const url = `./.netlify/functions/emails/SignUp`;
// const email = requestBody.subscriberEmail;
// console.log("Using URL:", url);
// //automatically generated snippet from the email preview
// //sends a request to an email handler for a subscribed email
// try {
// await fetch(`/.netlify/functions/emails/SignUp`, {
// headers: {
// "netlify-emails-secret": process.env.NEXT_PUBLIC_NETLIFY_EMAILS_SECRET,
// },
// method: "POST",
// body: JSON.stringify({
// from: process.env.NEXT_PUBLIC_NETLIFY_FROM_EMAIL,
// to: email,
// subject: "Thanks For Signing Up on Sign365",
// parameters: {
// email: email,
// },
// }),
// });
// } catch (err) {
// console.log("Error sending Mailchimp email", err.message);
// return {
// statusCode: 500,
// body: JSON.stringify("Failed to send Mailchimp email."),
// headers: {
// "Access-Control-Allow-Origin": "*",
// "Access-Control-Allow-Headers": "Content-Type"
// }
// };
// }
// }