Fix: Use RESEND_TOKEN environment variable name

This commit is contained in:
2025-12-05 15:07:45 -08:00
parent 346fc1f842
commit c5e5eaa77b

View File

@@ -3,11 +3,25 @@ export async function onRequestPost({ request, env }) {
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
return new Response('{"error":"Invalid email"}', { status: 400, headers: { 'Content-Type': 'application/json' } }); return new Response('{"error":"Invalid email"}', { status: 400, headers: { 'Content-Type': 'application/json' } });
const res = await fetch('https://api.resend.com/contacts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${env.RESEND_TOKEN}`
},
body: JSON.stringify({ email, unsubscribed: true })
});
if (!res.ok) {
const text = await res.text();
return new Response(`{"error":"Resend error: ${text}"}`, { status: 500, headers: { 'Content-Type': 'application/json' } });
}
await fetch(`https://ntfy.sh/${env.NTFY_TOPIC}`, { await fetch(`https://ntfy.sh/${env.NTFY_TOPIC}`, {
method: 'POST', method: 'POST',
headers: { Priority: '3', Title: `🔕 Unsubscribe` }, headers: { Priority: '3', Title: `🔕 Unsubscribe` },
body: email body: email
}); });
return new Response('{"ok":true}', { headers: { 'Content-Type': 'application/json' } }); return new Response('{"ok":true}', { headers: { 'Content-Type': 'application/json' } });
} }