From 0a842a3f947ac65be2e65003dac803b3a7137aeb Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Fri, 5 Dec 2025 15:03:42 -0800 Subject: [PATCH] Feat: Send ntfy notification alongside Resend contact creation --- functions/api/subscribe.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/functions/api/subscribe.js b/functions/api/subscribe.js index 1e1cfcd..35f6e32 100644 --- a/functions/api/subscribe.js +++ b/functions/api/subscribe.js @@ -3,6 +3,9 @@ export async function onRequestPost({ request, env }) { if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) return new Response('{"error":"Invalid email"}', { status: 400, headers: { 'Content-Type': 'application/json' } }); + const c = request.cf || {}; + const geo = [c.city, c.region, c.country].filter(Boolean).join(', ') || 'Unknown'; + const res = await fetch('https://api.resend.com/contacts', { method: 'POST', headers: { @@ -17,5 +20,11 @@ export async function onRequestPost({ request, env }) { return new Response(`{"error":"Resend error: ${text}"}`, { status: 500, headers: { 'Content-Type': 'application/json' } }); } + await fetch(`https://ntfy.sh/${env.NTFY_TOPIC}`, { + method: 'POST', + headers: { Priority: '3', Title: `📬 ${geo}` }, + body: email + }); + return new Response('{"ok":true}', { headers: { 'Content-Type': 'application/json' } }); }