let { submittedEmailAddresses } = await import("https://esm.town/v/klepra/submittedEmailAddresses");
export const renderFormAndSaveData = (req: express.Request, res: express.Response) => {
if (req.method === "GET") {
return res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Email Form</title>
</head>
<body>
<!-- Change the action here to THIS val's Express endpoint! -->
<form action="https://vtdocs-renderFormAndSaveData.express.val.run" method="post">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
`);
}
if (submittedEmailAddresses === undefined) {
submittedEmailAddresses = [];
}
const emailAddress = req.body.email;
if (submittedEmailAddresses.includes(emailAddress)) {
return res.send("you're already signed up!");
}
console.email(`${emailAddress} just signed up!`, "new sign up");
submittedEmailAddresses.push(emailAddress);
return res.send("thanks! you're signed up!");
};