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>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.content {
background-color: #3498db;
color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.form-group {
margin: 10px 0;
}
.button {
background-color: white;
color: #3498db;
border: 1px solid #3498db;
border-radius: 5px;
padding: 5px 10px;
cursor: pointer;
}
.button:hover {
background-color: #2980b9;
color: white;
}
</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" },
});
}