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 htmlResponse = `
<style>
body { font-family: Arial, sans-serif; text-align: center; }
h1 { color: #333; }
form { margin-top: 20px; }
input[type="text"], input[type="submit"] { padding: 5px; margin: 5px; }
</style>
<h1>Hello, ${name}!</h1>
`;
return new Response(htmlResponse, {
headers: { "Content-Type": "text/html" },
});
} else {
const htmlForm = `
<style>
body { font-family: Arial, sans-serif; text-align: center; }
form { margin-top: 20px; }
input[type="text"], input[type="submit"] { padding: 5px; margin: 5px; }
</style>
<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>
`;
return new Response(htmlForm, {
headers: { "Content-Type": "text/html" },
});
}
}