Files
portfolio/app/api/content/page/route.ts
Cursor Agent fbce838d3f fix(consent): avoid banner flashing on reload
Initialize consent state from cookie synchronously so the banner only shows when no choice was made.

fix(api): fail-soft when DB schema missing

Return null/empty content for CMS endpoints when migrations are not applied instead of crashing with Prisma P2021/P2022.

fix(n8n): parse status response defensively

Handle empty/invalid JSON bodies from n8n to prevent activity feed from getting stuck.

Co-authored-by: dennis <dennis@konkol.net>
2026-01-14 21:47:31 +00:00

26 lines
891 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { getContentByKey } from "@/lib/content";
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const key = searchParams.get("key");
const locale = searchParams.get("locale") || "en";
if (!key) {
return NextResponse.json({ error: "key is required" }, { status: 400 });
}
try {
const translation = await getContentByKey({ key, locale });
if (!translation) return NextResponse.json({ content: null });
return NextResponse.json({ content: translation });
} catch (error) {
// If DB isn't migrated/available, fail soft so the UI can fall back to next-intl strings.
if (process.env.NODE_ENV === "development") {
console.warn("Content API failed; returning null content:", error);
}
return NextResponse.json({ content: null });
}
}