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=Poppins:wght@600&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(to right, #ff7e5f, #feb47b);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
color: #fff;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
.content {
background-color: rgba(0, 0, 0, 0.5);
padding: 30px;
border-radius: 15px;
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2);
text-align: center;
}
.form-group {
margin: 20px 0;
}
.button {
background-color: #ff7e5f;
color: white;
border: 2px solid white;
border-radius: 25px;
padding: 10px 20px;
cursor: pointer;
transition: all 0.3s ease;
}
.button:hover {
background-color: white;
color: #ff7e5f;
}
input[type="text"] {
padding: 8px;
border-radius: 8px;
border: none;
outline: none;
margin-top: 10px;
}
</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" },
});
}