1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { set } from "https://esm.town/v/std/set?v=11";
import { email } from "https://esm.town/v/std/email?v=9";
let { submittedEmailAddresses } = await import("https://esm.town/v/yurivish/submittedEmailAddresses");
export const iopEmail = async (req: Request) => {
// Create somewhere to store data if it doesn't already exist
if (submittedEmailAddresses === undefined) {
submittedEmailAddresses = [];
}
// Pick out the form data
const formData = await req.formData();
const emailAddress = formData.get("email") as string;
const init = { headers: { "Content-Type": "text/html" } };
if (submittedEmailAddresses.includes(emailAddress)) {
// return new Response("you're already signed up!", init);
return Response.redirect("https://iop.systems/signed-up");
}
await email({
text: `${emailAddress} just signed up!`,
subject: "new sign up",
});
// Store form data
submittedEmailAddresses.push(emailAddress);
await set(
"submittedEmailAddresses",
submittedEmailAddresses,
);
// return new Response("thanks! you're signed up!", init);
return Response.redirect("https://iop.systems/signed-up");
};