AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
site: capture all email forms to R2 via a Pages Function
xerj-org1a6d25848b1c
diff --git a/functions/lead.js b/functions/lead.jsnew file mode 100644index 000000000..9c16eabc4--- /dev/null+++ b/functions/lead.js@@ -0,0 +1,64 @@+// /lead — capture a work email to R2 (bucket bound as LEADS), and export+// captured leads behind a secret token.+// POST /lead {"email": "..."} -> store one lead+// GET /lead?token=SECRET&format=json|csv -> list all leads+// GET /lead -> harmless hint+// The client POST is fire-and-forget, so it must never block the redirect.++const JSON_HEADERS = { 'content-type': 'application/json', 'cache-control': 'no-store' };++export async function onRequestPost({ request, env }) {+ try {+ const body = await request.json().catch(() => ({}));+ const email = String(body.email || '').trim().toLowerCase();+ if (!email || !email.includes('@') || email.length > 254) {+ return new Response(JSON.stringify({ ok: false, error: 'invalid email' }), { status: 400, headers: JSON_HEADERS });+ }+ if (!env.LEADS) {+ console.log('[lead] no R2 binding; email=', email);+ return new Response(JSON.stringify({ ok: true, stored: false }), { headers: JSON_HEADERS });+ }+ const now = new Date().toISOString();+ const record = {+ email,+ ts: now,+ source: String(body.source || 'landing'),+ ua: request.headers.get('user-agent') || '',+ referer: request.headers.get('referer') || '',+ ip: request.headers.get('cf-connecting-ip') || '',+ country: (request.cf && request.cf.country) || '',+ };+ const key = `leads/${now}_${crypto.randomUUID()}.json`;+ await env.LEADS.put(key, JSON.stringify(record), { httpMetadata: { contentType: 'application/json' } });+ return new Response(JSON.stringify({ ok: true, stored: true }), { headers: JSON_HEADERS });+ } catch (e) {+ return new Response(JSON.stringify({ ok: false, error: String(e) }), { status: 500, headers: JSON_HEADERS });+ }+}++export async function onRequestGet({ request, env }) {+ const url = new URL(request.url);+ const token = url.searchParams.get('token');+ // Export requires the secret token AND a configured LEADS_TOKEN.+ if (token && env.LEADS_TOKEN && token === env.LEADS_TOKEN && env.LEADS) {+ const leads = [];+ let cursor;+ do {+ const page = await env.LEADS.list({ prefix: 'leads/', limit: 1000, cursor });+ for (const obj of page.objects) {+ const o = await env.LEADS.get(obj.key);+ if (o) { try { const r = JSON.parse(await o.text()); r._key = obj.key; leads.push(r); } catch (_) {} }+ }+ cursor = page.truncated ? page.cursor : undefined;+ } while (cursor);+ leads.sort((a, b) => (a.ts < b.ts ? 1 : -1));+ if (url.searchParams.get('format') === 'csv') {+ const esc = (v) => '"' + String(v == null ? '' : v).replace(/"/g, '""') + '"';+ const rows = [['ts', 'email', 'source', 'country', 'referer', 'ip', 'ua'].join(',')];+ for (const l of leads) rows.push([l.ts, l.email, l.source, l.country, l.referer, l.ip, l.ua].map(esc).join(','));+ return new Response(rows.join('\n'), { headers: { 'content-type': 'text/csv; charset=utf-8', 'cache-control': 'no-store' } });+ }+ return new Response(JSON.stringify({ ok: true, count: leads.length, leads }, null, 2), { headers: JSON_HEADERS });+ }+ return new Response(JSON.stringify({ ok: true, hint: 'POST {"email":"[email protected]"} to capture a lead' }), { headers: JSON_HEADERS });+}diff --git a/landing/index.html b/landing/index.htmlindex bd6128d40..349d4a48f 100644--- a/landing/index.html+++ b/landing/index.html@@ -216,7 +216,7 @@<input type="email" name="email" placeholder="[email protected]" required aria-label="Work email" autocomplete="email" /></div><button type="submit" class="demo">OPEN PLAYGROUND <span class="arrow">→</span></button>- <span class="note">Stored only in your browser. No server, no sales call. Ever.</span>+ <span class="note">We keep your email to follow up about XERJ — nothing else. No spam, no reselling.</span></form></section>@@ -289,9 +289,12 @@const email = form.querySelector('input[type=email]').value.trim();if (!email || !email.includes('@')) return;console.log('[xerj lead]', email);- // Stored only in the browser (same gate key as the playground page),- // then open the live dashboards app — no server, no "inbox" wait.try { localStorage.setItem('xerj.playground.email', email); } catch (_) {}+ // Capture the lead (fire-and-forget with keepalive so the redirect+ // never waits on it), then open the live dashboards app.+ try {+ fetch('/lead', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ email: email, source: 'landing' }), keepalive: true }).catch(function () {});+ } catch (_) {}window.location.href = '/playground/';});}diff --git a/landing/playground.html b/landing/playground.htmlindex a8efd8eba..7f7fa472e 100644--- a/landing/playground.html+++ b/landing/playground.html@@ -71,7 +71,7 @@</form><p class="fine">- WE ONLY STORE THIS IN YOUR BROWSER · NO PASSWORD · NO FUNNEL · CLEAR IT ANY TIME WITH <code class="inline">localStorage.clear()</code>+ STORED SO WE CAN FOLLOW UP ABOUT XERJ · NO PASSWORD · NO SPAM · CLEAR YOUR LOCAL COPY ANY TIME WITH <code class="inline">localStorage.clear()</code></p><!-- UNLOCKED STATE · revealed once gate is cleared -->@@ -146,6 +146,9 @@if (!email || !email.includes('@')) return;localStorage.setItem(GATE_KEY, email);console.log('[xerj playground gate]', email);+ try {+ fetch('/lead', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ email: email, source: 'playground-gate' }), keepalive: true }).catch(function () {});+ } catch (_) {}unlock(email);// Don't auto-redirect — let the user click LAUNCH so the// unlocked state is visible (and so back-button behaviourdiff --git a/landing/product.html b/landing/product.htmlindex 66a6381b6..bb9e67074 100644--- a/landing/product.html+++ b/landing/product.html@@ -90,7 +90,6 @@<span class="arrow">→</span></button><span class="note">OR <a href="/playground.html" class="accent">OPEN THE PLAYGROUND</a> · UNLOCK WITH ONE EMAIL · FULL UX</span>- <span class="ok">✓ THANKS. CHECK YOUR INBOX WITHIN 24 HOURS.</span></form></section>@@ -598,7 +597,9 @@const email = form.querySelector('input[type=email]').value.trim();if (!email || !email.includes('@')) return;console.log('[xerj lead]', email);- form.classList.add('sent');+ try { localStorage.setItem('xerj.playground.email', email); } catch (_) {}+ try { fetch('/lead', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ email: email, source: 'product' }), keepalive: true }).catch(function () {}); } catch (_) {}+ window.location.href = '/playground/';});}})();diff --git a/landing/use-cases.html b/landing/use-cases.htmlindex 7cdd1e085..fae225b74 100644--- a/landing/use-cases.html+++ b/landing/use-cases.html@@ -400,8 +400,7 @@<form class="lead-form" id="leadForm" action="#" method="post" novalidate><input type="email" name="email" placeholder="[email protected]" required aria-label="Work email" autocomplete="email" /><button type="submit" class="demo">SEE THE DEMO <span class="arrow">→</span></button>- <span class="note">We only use this email to send you the binary. Ever.</span>- <span class="ok">✓ THANKS. CHECK YOUR INBOX WITHIN 24 HOURS.</span>+ <span class="note">We keep your email to follow up about XERJ — nothing else. No spam, no reselling.</span></form></section>@@ -430,7 +429,9 @@const email = form.querySelector('input[type=email]').value.trim();if (!email || !email.includes('@')) return;console.log('[xerj lead]', email);- form.classList.add('sent');+ try { localStorage.setItem('xerj.playground.email', email); } catch (_) {}+ try { fetch('/lead', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ email: email, source: 'use-cases' }), keepalive: true }).catch(function () {}); } catch (_) {}+ window.location.href = '/playground/';});}})();diff --git a/wrangler.toml b/wrangler.tomlnew file mode 100644index 000000000..591ad5629--- /dev/null+++ b/wrangler.toml@@ -0,0 +1,9 @@+# Cloudflare Pages project config for the xerj marketing site + Functions.+# Binds the R2 bucket that /functions/lead.js writes captured emails to.+name = "xerj"+pages_build_output_dir = "landing"+compatibility_date = "2024-09-01"++[[r2_buckets]]+binding = "LEADS"+bucket_name = "xerj-leads"