Public
HTTP
parkerdavis-linksform.web.val.run
October 23, 2023
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
31
32
33
34
35
36
37
38
39
40
41
42
import { html } from "https://esm.town/v/parkerdavis/html";
import { set } from "https://esm.town/v/std/set?v=11";
import { linksFormData } from "https://esm.town/v/parkerdavis/linksFormData";
import { email as email2 } from "https://esm.town/v/std/email?v=9";
export let linksForm = async (req: Request) => {
if (req.method === "POST") {
let formData = await req.formData();
let data = {
email: formData.get("email"),
message: formData.get("message"),
time: Date.now(),
};
await email2({
text: data,
subject: "Links form submission received!",
});
linksFormData.push(data);
await set("linksFormData", linksFormData);
return html(
`
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="refresh" content="3; url='https://links.parkerdavis.dev'" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<p>Hey thanks for the message!</p>
<p>You will be redirected back to <a href="https://links.parkerdavis.dev">https://links.parkerdavis.dev</a> in a few seconds.
</body>
</html>
`,
{
headers: {
"Set-Cookie": `email=${formData.get("email")}`,
},
},
);
}
return html("Hello!");
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023