feat(api): add SSR config update endpoints and DSGVO contact processing
This commit is contained in:
30
src/pages/api/contact.ts
Normal file
30
src/pages/api/contact.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { loadWaasConfigs } from '../../utils/configLoader';
|
||||
import nodemailer from 'nodemailer';
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
const data = await request.formData();
|
||||
const name = data.get('name')?.toString() || '';
|
||||
const email = data.get('email')?.toString() || '';
|
||||
const message = data.get('message')?.toString() || '';
|
||||
|
||||
if (!name || !email || !message) {
|
||||
return new Response(JSON.stringify({ success: false, message: 'Bitte füllen Sie alle Pflichtfelder aus.' }), { status: 400, headers: { 'Content-Type': 'application/json' } });
|
||||
}
|
||||
|
||||
const { smtpConfig, siteConfig } = loadWaasConfigs();
|
||||
|
||||
if (!smtpConfig.isConfigured || smtpConfig.host === 'smtp.placeholder.local') {
|
||||
console.log('[WaaS Contact API] (Demo Mode) Received Submission:', { name, email, message });
|
||||
return new Response(JSON.stringify({ success: true, mode: 'placeholder', message: 'Anfrage erfolgreich empfangen! (Demo-Modus)' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport({ host: smtpConfig.host, port: smtpConfig.port, secure: smtpConfig.secure, auth: { user: smtpConfig.user, pass: smtpConfig.pass } });
|
||||
const sender = smtpConfig.fromName + ' ' + smtpConfig.fromEmail;
|
||||
await transporter.sendMail({ from: sender, to: siteConfig.contact.recipientEmail, replyTo: email, subject: '[Webseite] Neue Nachricht von ' + name, text: 'Name: ' + name + '\nEmail: ' + email + '\n\nNachricht:\n' + message });
|
||||
return new Response(JSON.stringify({ success: true, message: 'Vielen Dank für Ihre Anfrage! Wir melden uns umgehend.' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
||||
} catch (err: any) {
|
||||
return new Response(JSON.stringify({ success: false, message: 'Fehler beim Senden: ' + err.message }), { status: 500, headers: { 'Content-Type': 'application/json' } });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user