export default async function (req: Request): Promise<Response> {
if (req.method === "POST") {
const formData = new URLSearchParams(await req.text());
const name = formData.get("name") ?? "Stranger";
return new Response(`<h1 style="color: #333; text-align: center;">Hello, ${name}!</h1>`, { headers: { "Content-Type": "text/html" } });
}
return new Response(`
<html>
<head>
<title>Greetings Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
margin: 0;
padding: 10px;
}
h1 {
color: #27ae60;
text-align: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
}
label {
font-size: 1.2em;
margin-bottom: 5px;
color: #333;
}
input[type="text"] {
padding: 5px;
width: 200px;
border: 1px solid #333;
border-radius: 5px;
}
button {
padding: 8px 15px;
margin-top: 10px;
background-color: #27ae60;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #2ecc71;
}
</style>
</head>
<body>
<h1>Welcome!</h1>
<form method="post">
<label for="name">Enter your name:</label>
<input type="text" id="name" name="name">
<button type="submit">Submit</button>
</form>
</body>
</html>
`, { headers: { "Content-Type": "text/html" } });
}