Files
shop/server/api/contact.post.ts
Michael Czechowski 44107c0734
Some checks failed
Build and publish / build (push) Failing after 19s
feat: extract shop from mp/shop — initial libreshop/shop
Source moved verbatim from mp/shop/ on 2026-04-29; mp was the first
concrete adapter consuming the libreshop toolkit. Builds and publishes
git.librete.ch/libreshop/shop on every main / v* push via the standard
.gitea/workflows/build.yml shared across libreshop components.
2026-04-29 17:48:56 +02:00

56 lines
1.2 KiB
TypeScript

export default defineEventHandler(async (event) => {
const body = await readBody(event);
const { name, email, subject, message } = body;
if (!name || !email || !message) {
throw createError({
statusCode: 400,
message: "Name, E-Mail und Nachricht sind erforderlich",
});
}
// Validate email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
throw createError({
statusCode: 400,
message: "Ungültige E-Mail-Adresse",
});
}
try {
// Send email via Mail service
const config = useRuntimeConfig();
const mailApiUrl = config.mailApiUrl || "http://mail:2222";
await $fetch(`${mailApiUrl}/send`, {
method: "POST",
body: {
to: "paperwork@muellerprints.de",
subject: `Kontaktanfrage: ${subject || "Anfrage über Website"}`,
body: `
Name: ${name}
E-Mail: ${email}
Betreff: ${subject || "Kontaktanfrage über Website"}
Nachricht:
${message}
---
Diese Nachricht wurde über das Kontaktformular auf muellerprints.de gesendet.
`.trim(),
replyTo: email,
},
});
return { success: true };
} catch (error) {
console.error("Failed to send contact email:", error);
throw createError({
statusCode: 500,
message: "E-Mail konnte nicht gesendet werden",
});
}
});