Comments and a contact form on a static site
This site is static HTML, so it has nowhere to receive a form. The contact form on the front page and the comments under project posts are handled by a small Cloudflare Worker with a D1 database (Cloudflare’s SQLite), on the free tier. Emails go out through Mailjet.
reader --POST /comments--> Worker --> D1 (status = pending) --> email to me (signed link)
me --open link-------> approve | delete | reply --> approved comments appear on the post
page --GET /comments---> approved comments as JSON (email is never returned)
reader --POST /contact---> Worker --> email to me, Reply-To = the visitor
Spam
Cloudflare Turnstile checks that a visitor is a person, and the forms also have a hidden field that only bots fill in. A comment is stored as pending, and nothing becomes public until I approve it. The email I get has a signed link to approve, delete or reply to the comment. A reply shows under the comment, and is emailed to the commenter if they left an address.
Behind the site’s own domain
The Worker lives at a workers.dev address, but the page talks to /feedback/ on this site. nginx on the VM proxies that path to the Worker, so the Worker’s address stays out of the page source, and visitors only ever see this site’s domain.
The Mailjet lesson
Mailjet can send for a domain you’ve verified, so the mails go out from an address on my own domain. I first tried a free-mail address as the sender. Mailjet can’t authenticate those, and the notification emails just sat in its queue. The fix was a sender on my own domain, where DKIM passes.
Tests
The Worker’s logic has tests that run without a Cloudflare account or network, with Node’s built-in SQLite standing in for D1.
What it stores
Comments (name, optional email, text) sit in the database. Contact messages aren’t stored, they are only emailed. The privacy page has the details.
Loading comments…