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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This val serves an HTML page with a form to enter your name.
// When the form is submitted, it greets you with "Hello, <name>!".
export default async function(req: Request): Promise<Response> {
let name = "";
if (req.method === "POST") {
const formData = await req.formData();
name = formData.get("name") as string || "";
}
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@400;700&display=swap');
body {
font-family: 'Raleway', sans-serif;
background: linear-gradient(45deg, #ff6b6b, #f06595);
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.content {
background-color: rgba(255, 255, 255, 0.2);
padding: 30px;
border-radius: 15px;
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2);
text-align: center;
}
h1 {
margin-bottom: 20px;
}
.form-group {
margin: 20px 0;
}
input[type="text"] {
padding: 10px;
border: none;
border-radius: 5px;
width: 80%;
font-size: 1.1em;
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1);
}
.button {
background-color: #ffffff;
color: #ff6b6b;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 1.1em;
font-weight: bold;
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1);
cursor: pointer;
transition: background-color 0.3s, transform 0.3s;
}
.button:hover {
background-color: #f06595;
color: #ffffff;
transform: scale(1.05);
}
</style>
</head>
<body>
<div class="content">
<h1>Hello ${name ? `, ${name}` : "World"}!</h1>
<form method="POST">
<div class="form-group">
<label for="name">Enter your name:</label>
<input type="text" id="name" name="name">
</div>
<button type="submit" class="button">Submit</button>
</form>
</div>
</body>
</html>
`;
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
}