Sostituisce Resend con Cloudflare Email Service.
Usa il binding EMAIL per contatti e newsletter, eliminando la dipendenza da Resend e dalle relative API key. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -2,6 +2,7 @@ import type { APIRoute } from 'astro';
|
||||
import {
|
||||
absoluteUrl,
|
||||
createToken,
|
||||
getEmailBinding,
|
||||
getNewsletterDb,
|
||||
getRuntimeEnv,
|
||||
isValidEmail,
|
||||
@ -9,7 +10,7 @@ import {
|
||||
readEnv,
|
||||
required,
|
||||
sanitizeRedirect,
|
||||
sendWithResend,
|
||||
sendCloudflareEmail,
|
||||
siteOrigin,
|
||||
verifyTurnstile,
|
||||
type NewsletterSubscriber,
|
||||
@ -118,9 +119,7 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
||||
});
|
||||
}
|
||||
|
||||
const resendApiKey =
|
||||
readEnv('NEWSLETTER_RESEND_API_KEY', runtimeEnv) ||
|
||||
readEnv('CONTACT_FORM_RESEND_API_KEY', runtimeEnv);
|
||||
const emailBinding = getEmailBinding(runtimeEnv);
|
||||
const fromEmail =
|
||||
readEnv('NEWSLETTER_FROM_EMAIL', runtimeEnv) ||
|
||||
readEnv('CONTACT_FORM_FROM_EMAIL', runtimeEnv);
|
||||
@ -128,9 +127,9 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
||||
readEnv('NEWSLETTER_NOTIFY_TO_EMAIL', runtimeEnv) ||
|
||||
readEnv('CONTACT_FORM_TO_EMAIL', runtimeEnv);
|
||||
|
||||
if (!resendApiKey || !fromEmail) {
|
||||
if (!emailBinding || !fromEmail) {
|
||||
return new Response(
|
||||
'Live mode requires NEWSLETTER_RESEND_API_KEY (or CONTACT_FORM_RESEND_API_KEY) and NEWSLETTER_FROM_EMAIL (or CONTACT_FORM_FROM_EMAIL).',
|
||||
'Live mode requires EMAIL binding (Cloudflare Email Service) and NEWSLETTER_FROM_EMAIL (or CONTACT_FORM_FROM_EMAIL).',
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
@ -173,8 +172,7 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
||||
|
||||
const copy = confirmEmailCopy(locale, confirmUrl);
|
||||
try {
|
||||
await sendWithResend({
|
||||
apiKey: resendApiKey,
|
||||
await sendCloudflareEmail(emailBinding, {
|
||||
fromEmail,
|
||||
toEmail: email,
|
||||
subject: copy.subject,
|
||||
@ -187,8 +185,7 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
||||
|
||||
if (notifyTo) {
|
||||
try {
|
||||
await sendWithResend({
|
||||
apiKey: resendApiKey,
|
||||
await sendCloudflareEmail(emailBinding, {
|
||||
fromEmail,
|
||||
toEmail: notifyTo,
|
||||
subject: required(form.get('_subject')) || 'Nuova richiesta newsletter — NexStudio',
|
||||
|
||||
Reference in New Issue
Block a user