Contact form: send through a Worker, Resend and Turnstile - #8
Merged
Conversation
…nstile The form used to open the visitor's mail app, which does nothing for anyone using webmail. It now posts to /api/contact, served by a small Worker script next to the static assets (run_worker_first: /api/*): - checks method, same origin, body size and fields; a honeypot drops bots quietly - verifies the Cloudflare Turnstile token (hostname and action included) - emails the message through Resend with the visitor as Reply-To, plain text only - fails closed (503) without its secrets; the form then points to email Until a Turnstile site key is set in src/config/site.ts, the page shows a plain email link instead of the form. Local end-to-end runs use Cloudflare's test keys and a dry run (npm run preview). Secrets stay in Cloudflare. Also: Giscus strict title matching, set before the first thread exists. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The contact form used to open the visitor's mail app, which does nothing for anyone on webmail. It now sends the message.
How it works
/api/contact, served by a small Worker script next to the static assets (run_worker_first: ["/api/*"]); every other request is still a static file.src/config/site.ts, the page shows a plain email link instead of the form, so merging this changes nothing visible yet.Also: Giscus strict title matching, set before the first comment thread exists.
Verified
npm run check: lint, both typechecks (site + worker), format, 41 tests (24 new for the Worker).wrangler devand Cloudflare's test keys: form sent, email built with the right recipient, Reply-To and subject (dry run); "send another" gets a fresh token.To activate (after deploy)
Resend domain
mail.omercelik.dev, a Turnstile widget, thenRESEND_API_KEYandTURNSTILE_SECRET_KEYas Worker secrets and the site key insite.ts. See README → Contact form.🤖 Generated with Claude Code