feat: add internal_component block type with contact form
InternalComponentBlock dispatches on `component` field value. ContactFormComponent submits via /api/contact (SvelteKit proxy → CMS /api/forms/kontakt/submit) with honeypot + client_age_ms. BlockRenderer and block-types.ts updated accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { json } from "@sveltejs/kit";
|
||||
import { env } from "$env/dynamic/private";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, getClientAddress }) => {
|
||||
const body = await request.json().catch(() => null);
|
||||
if (!body || typeof body !== "object") {
|
||||
return json({ error: "Ungültige Anfrage" }, { status: 400 });
|
||||
}
|
||||
|
||||
const cmsBase = (env.PUBLIC_CMS_URL || "http://localhost:3000").replace(/\/$/, "");
|
||||
const cmsEnv = env.PUBLIC_CMS_ENV || "";
|
||||
const url = cmsEnv
|
||||
? `${cmsBase}/api/forms/kontakt/submit?_environment=${encodeURIComponent(cmsEnv)}`
|
||||
: `${cmsBase}/api/forms/kontakt/submit`;
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Forwarded-For": getClientAddress(),
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
return json({ ok: true }, { status: 201 });
|
||||
}
|
||||
|
||||
const text = await res.text().catch(() => "");
|
||||
return json({ error: text || "Fehler beim Senden" }, { status: res.status });
|
||||
};
|
||||
Reference in New Issue
Block a user