ยฉ 2026 Hedgehog Software, LLC
// using the Nuxt UI form async function onSubmit(event: FormSubmitEvent<Contact>) { await $fetch('/api/contact', { method: 'POST', body: event.data, }); // clear form // add a success toast }
// ... imports const runtimeConfig = useRuntimeConfig() type Contact = z.infer<typeof contactSchema> const resend = new Resend(runtimeConfig.resendAPIKey) export default defineEventHandler(async (event) => { try { const { customerRequestRecipientEmail } = runtimeConfig; if (!customerRequestRecipientEmail) { sendError(event, createError({ statusCode: 400, statusMessage: '...', })) return } const body = await readBody<Contact>(event); const createEmailResponse = await resend.emails.send({ from: body.mail, to: [customerRequestRecipientEmail], subject: '...', text: JSON.stringify(body) // good enough }); if (!createEmailResponse.error) { return } sendError(event, createError({ statusCode: 500, statusMessage: createEmailResponse.error.message, })) } catch (error) { // send 500 error } });
WARN [Vue Router warn]: No match found for location with path "/api/contact"
{ "error": true, "url": "http://localhost:3000/api/contact", "statusCode": 404, "statusMessage": "Page not found: /api/contact", "message": "Page not found: /api/contact", "data": { "path": "/api/contact" } }