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";
const greeting = `Hello, ${name}!`;
const funFact = "Did you know that the first email was sent in 1971?";
const htmlResponse = `
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
text-align: center;
padding: 20px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333333;
}
p {
color: #666666;
}
input[type="text"] {
padding: 8px;
margin: 10px 0;
width: 200px;
border: 1px solid #cccccc;
border-radius: 5px;
}
input[type="submit"] {
padding: 8px 20px;
background-color: #007bff;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
<div class="container">
<h1>${greeting}</h1>
<p>${funFact}</p>
<form action="/" method="POST">
<label for="name">Enter your name:</label><br>
<input type="text" id="name" name="name"><br>
<input type="submit" value="Submit">
</form>
</div>
`;
return new Response(htmlResponse, {
headers: { "Content-Type": "text/html" },
});
} else {
const htmlForm = `
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
text-align: center;
padding: 20px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
input[type="text"] {
padding: 8px;
margin: 10px 0;
width: 200px;
border: 1px solid #cccccc;
border-radius: 5px;
}
input[type="submit"] {
padding: 8px 20px;
background-color: #007bff;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
<div class="container">
<form action="/" method="POST">