A simple Cloudflare Worker to handle email signups for a waiting list.
-
Install dependencies:
pnpm install
-
Copy the example config:
cp wrangler.toml.example wrangler.toml
-
Create a KV namespace:
wrangler kv namespace create "<YOUR_KV_NAME>" wrangler kv namespace create "<YOUR_KV_NAME>" --preview
-
Update
wrangler.toml
with your KV namespace IDs from the output above. -
Deploy:
pnpm deploy
Add an email to the waitlist.
Request:
{
"email": "user@example.com"
}
Response:
{
"success": true,
"message": "Successfully added to waitlist"
}
Run locally:
pnpm dev
<form id="waitlist-form">
<input type="email" id="email" required>
<button type="submit">Join Waitlist</button>
</form>
<script>
document.getElementById('waitlist-form').addEventListener('submit', async (e) => {
e.preventDefault();
const email = document.getElementById('email').value;
const response = await fetch('https://your-worker.workers.dev/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
const data = await response.json();
alert(data.message);
});
</script>