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; }
input[type="text"] { padding: 8px; margin: 5px; }
input[type="submit"] { padding: 8px 20px; background-color: #4CAF50; color: white; border: none; cursor: pointer; }
</style>
<h1 style="color: #333;">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; }
input[type="text"] { padding: 8px; margin: 5px; }
input[type="submit"] { padding: 8px 20px; background-color: #4CAF50; color: white; border: none; cursor: pointer; }
</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" },
});
}
}