import { NextResponse } from "next/server"; import { isLocale, LOCALE_COOKIE } from "@/lib/i18n"; import { isSameOrigin } from "@/lib/origin"; // Setzt das Sprach-Cookie. Kein Login nötig (auch anonyme Besucher // der öffentlichen Speisekarte sollen die Sprache wechseln können). export async function POST(request: Request) { if (!isSameOrigin(request)) { return NextResponse.json({ error: "Nicht erlaubt." }, { status: 403 }); } const body = await request.json().catch(() => null); const locale = body?.locale; if (!isLocale(locale)) { return NextResponse.json({ error: "Ungültige Sprache." }, { status: 400 }); } const response = NextResponse.json({ ok: true }); response.cookies.set(LOCALE_COOKIE, locale, { path: "/", maxAge: 60 * 60 * 24 * 365, sameSite: "lax", }); return response; }