Files
shop/server/api/contact.post.ts
T
libretech d46bc9380e
build / test (push) Successful in 10s
build / build (push) Skipped
Checkout: forward only the checkout fields, show clear errors, fix the contact form (#16)
Co-authored-by: Michael Czechowski <mail@librete.ch>
2026-10-15 10:31:57 +02:00

19 lines
631 B
TypeScript

import { contactMail, mailSendUrl } from "~/server/utils/contactMail";
export default defineEventHandler(async (event) => {
const result = contactMail(await readBody(event));
if (result.ok === false) {
throw createError({ statusCode: 400, message: result.message });
}
try {
const config = useRuntimeConfig();
await $fetch(mailSendUrl(config.mailApiUrl || "http://mail:2222"), { method: "POST", body: result.mail });
return { success: true };
} catch (error) {
console.error("Failed to send contact email:", error);
throw createError({ statusCode: 500, message: "E-Mail konnte nicht gesendet werden" });
}
});