Node.js/Express-Server als Ersatz für Cloudflare Pages Functions + D1 (läuft auf eigenem Server statt Cloudflare)
Build & Deploy / deploy (push) Waiting to run

This commit is contained in:
qcigano
2026-08-05 15:06:17 +02:00
parent 53e7bb158a
commit b8b8ec7b7a
19 changed files with 1322 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
/* =====================================================================
lib/email.js — E-Mail-Versand über Resend. 1:1 portiert aus functions/_shared/email.js.
sendeEmail() wirft NIE einen Fehler, gibt nur { ok, error? } zurück — eine fehlgeschlagene
E-Mail darf nie eine Bestellung zum Scheitern bringen (siehe bestellung-erstellen.js).
===================================================================== */
const RESEND_API_URL = "https://api.resend.com/emails";
const STANDARD_ABSENDER = "Van's DIY & Bastelbedarf <[email protected]>";
export async function sendeEmail({ to, subject, html, text, from }) {
if (!process.env.RESEND_API_KEY) {
return { ok: false, error: "RESEND_API_KEY nicht gesetzt — E-Mail-Versand noch nicht eingerichtet." };
}
try {
const res = await fetch(RESEND_API_URL, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.RESEND_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
from: from || process.env.RESEND_FROM || STANDARD_ABSENDER,
to: Array.isArray(to) ? to : [to],
subject,
html,
text,
}),
});
if (!res.ok) {
const fehlertext = await res.text().catch(() => "");
return { ok: false, error: `Resend antwortete mit Status ${res.status}: ${fehlertext}` };
}
return { ok: true };
} catch (err) {
return { ok: false, error: err instanceof Error ? err.message : String(err) };
}
}
export function escapeHtmlFuerEmail(str) {
return String(str ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
}