The Problem: Secure Lead Generation on a Static CMS
![]() |
| Image generated with Gemini AI |
When running a technical publication on static platforms or within the rigid confines of CMS architectures like Blogger, you immediately face a fundamental limitation: the lack of a custom backend to execute server-side application logic. Developers frequently compromise by embedding heavy third-party iframes or issuing unmediated JavaScript API requests directly to their email service provider (e.g., Brevo/Sendinblue).
From an IT security perspective, executing authenticated API calls from client-side browser code is a critical vulnerability: embedding your API_KEY in front-end assets leaves it exposed via browser developer tools (DevTools), allowing anyone to hijack quotas, exfiltrate metadata, or pollute your contact database.
The Solution: Serverless Middleware Powered by Cloudflare Workers
To eliminate credential exposure while maintaining sub-second latency, I built a serverless micro-proxy running on Cloudflare Workers. Acting as an isolated intermediary between the front-end form and Brevo's API, the architecture executes across 4 discrete stages:
- Client-Side Interception: The blog form captures user submission, extracts the target email, binds the active locale (
en), and attaches the secured resource URL. - Serverless Forwarding: The browser dispatches an unauthenticated JSON payload to our protected Cloudflare Worker HTTPS endpoint.
- Secret Injection: The Worker intercepts the request, injects the encrypted
BREVO_API_KEY(stored in Cloudflare environment secrets), and executes an authenticated machine-to-machine call to Brevo API v3. - Orchestrated Double Opt-in: Brevo validates the payload, generates a transactional confirmation token, and dispatches a localized verification email containing the single-use activation link.
Cloudflare Worker Implementation
The Worker enforces CORS constraints to accept requests exclusively from the designated domain while keeping the upstream API key completely isolated:
export default {
async fetch(request, env) {
if (request.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "https://itchronicle.com",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type"
}
});
}
if (request.method !== "POST") {
return new Response("Method not allowed", { status: 405 });
}
try {
const { email, lang, redirectUrl } = await request.json();
const templateId = lang === "en" ? 12 : 11;
const listId = lang === "en" ? 5 : 4;
const brevoPayload = {
email: email,
includeListIds: [listId],
templateId: templateId,
redirectionUrl: redirectUrl
};
const response = await fetch("https://api.brevo.com/v3/contacts/doubleOptinConfirmation", {
method: "POST",
headers: {
"api-key": env.BREVO_API_KEY,
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify(brevoPayload)
});
return new Response(JSON.stringify({ success: response.ok }), {
status: response.status,
headers: {
"Access-Control-Allow-Origin": "https://itchronicle.com",
"Content-Type": "application/json"
}
});
} catch (err) {
return new Response(JSON.stringify({ error: err.message }), { status: 500 });
}
}
};
Index: The Genesis of a Newsletter
- Ep. 1: Serverless Architecture with Cloudflare Workers and Brevo [You are here]
- Ep. 2: Git Subtree and Delivery Decoupling
- Ep. 3: Cloudflare Workers, Anti-Spam Protection & Rate Limiting at the Edge
- Ep. 4: Advanced Brevo API Error Handling on Cloudflare Workers
Access the IT Chronicle Asset Repository
Subscribe to access our centralized technical assets repository, containing all operational scripts (Active Directory Scanner, AI Privacy Tool, endpoint security scripts).
By submitting, you agree to receive IT Chronicle technical updates. Zero spam, pure operational architecture.

