Skip to content

Remove API route; submit to Brevo directly from client with fetch fallback#990

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/fix-brevo-style-issues
Draft

Remove API route; submit to Brevo directly from client with fetch fallback#990
Copilot wants to merge 7 commits intomainfrom
copilot/fix-brevo-style-issues

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

Newsletter subscription was routed through a Next.js API handler (/api/newsletter). The requirement is no API routes — submit directly to Brevo's hosted form endpoint from the client.

Changes

lib/newsletter.ts

  • Added shared EMAIL_RE regex and submitToBrevo(email) helper
  • POSTs application/x-www-form-urlencoded directly to BREVO_FORM_URL with mode: 'no-cors' (Brevo's endpoint doesn't emit CORS headers; response is opaque so any non-throwing fetch is treated as success)

hooks/use-newsletter-subscribe.ts

  • Replaced /api/newsletter fetch with submitToBrevo()
  • On failure: opens BREVO_FORM_URL in a new tab so the user is guaranteed to reach the form

components/book-promotion-popup.tsx

  • Same direct submitToBrevo() call replacing the previous /api/newsletter fetch
  • On failure: same window.open(BREVO_FORM_URL, '_blank') fallback with null-check for popup blockers

app/api/newsletter/route.ts

  • Deleted
// On fetch failure — both in hook and popup
} catch {
  const w = window.open(BREVO_FORM_URL, '_blank');
  if (!w) {
    console.warn('[newsletter] Popup blocked. Direct user to:', BREVO_FORM_URL);
  }
  setStatus('error');
}

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…roach)

Co-authored-by: bobbyiliev <21223421+bobbyiliev@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 5, 2026

Deploying devops-daily with  Cloudflare Pages  Cloudflare Pages

Latest commit: 55217ad
Status: ✅  Deploy successful!
Preview URL: https://d35d3adb.devops-daily.pages.dev
Branch Preview URL: https://copilot-fix-brevo-style-issu.devops-daily.pages.dev

View logs

Copilot AI changed the title [WIP] Fix Brevo styles to match site design Switch newsletter from Mailchimp to Brevo, keep existing styles Mar 5, 2026
… lib/newsletter.ts

Co-authored-by: bobbyiliev <21223421+bobbyiliev@users.noreply.github.com>
Copilot AI changed the title Switch newsletter from Mailchimp to Brevo, keep existing styles Switch newsletter from Mailchimp to Brevo Mar 5, 2026
Co-authored-by: bobbyiliev <21223421+bobbyiliev@users.noreply.github.com>
Copilot AI changed the title Switch newsletter from Mailchimp to Brevo Hardcode Brevo form URL instead of env var Mar 5, 2026
Co-authored-by: bobbyiliev <21223421+bobbyiliev@users.noreply.github.com>
Copilot AI changed the title Hardcode Brevo form URL instead of env var Fix newsletter subscribe navigating to blank Brevo page Mar 5, 2026
Co-authored-by: bobbyiliev <21223421+bobbyiliev@users.noreply.github.com>
Co-authored-by: bobbyiliev <21223421+bobbyiliev@users.noreply.github.com>
Copilot AI changed the title Fix newsletter subscribe navigating to blank Brevo page Remove API route; submit to Brevo directly from client with fetch fallback Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants