Cloudflare Worker that serves Resend email HTML via JWT-authenticated links.
- A request arrives with a
?token=query parameter containing a signed JWT - The worker verifies the JWT against
RESEND_JWT_SECRET(HS256) - Extracts the
email_idclaim from the token payload - Fetches the email HTML from the Resend API
- Returns the HTML with
Cache-Controlheaders derived from the token's expiry - Caches the response via the Cloudflare Cache API to avoid redundant Resend calls
| Variable | Description |
|---|---|
RESEND_API_KEY |
Resend API key |
RESEND_JWT_SECRET |
Shared secret used to sign/verify JWTs |
Set these as secrets in the Cloudflare dashboard or via wrangler secret put.
bun installbun run devbun run generate-jwt -- --secret "your-jwt-secret" --email-id "email-abc123" --expires-in 900- Authenticate with Cloudflare:
bunx wrangler login- Set the required secrets:
bunx wrangler secret put RESEND_API_KEY
bunx wrangler secret put RESEND_JWT_SECRETEach command will prompt you to paste the value interactively (it won't be echoed to the terminal).
- Deploy the worker:
bun run deploybun run deployTo update a secret, re-run the wrangler secret put command — it overwrites the existing value.
To list secrets (names only, values are never shown):
bunx wrangler secret listTo delete a secret:
bunx wrangler secret delete SECRET_NAMEYou can also manage secrets in the Cloudflare dashboard under Workers & Pages > resend-links > Settings > Variables and Secrets.
bun run cf-typegenThis writes worker-configuration.d.ts (git-ignored).
bun run lint # check
bun run format # auto-fixbun run typecheckTests use @cloudflare/vitest-pool-workers to run inside the Workers runtime.
bun run test