19 lines
631 B
TypeScript
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" });
|
|
}
|
|
});
|