import { NextResponse } from 'next/server'; import { revalidatePath } from 'next/cache'; // ADD THIS import { getPortals, savePortals } from '@/lib/db'; import { isValidHexColor, sanitizeWelcomeText } from '@/lib/sanitize'; import { validatePortal } from '@/lib/validation'; import { Portal } from '@/types'; export const dynamic = 'force-dynamic'; export async function GET() { const portals = await getPortals(); return NextResponse.json(portals[0] || null); } export async function POST(request: Request) { try { const incomingPortal: Portal = await request.json(); // Sanifica l'HTML del welcome text prima di validare la lunghezza, così il counter // riflette il contenuto effettivamente persistito. if (typeof incomingPortal.welcomeText === 'string') { incomingPortal.welcomeText = sanitizeWelcomeText(incomingPortal.welcomeText); } const { valid, errors } = validatePortal(incomingPortal); if (!valid) { return NextResponse.json({ error: 'Validation failed', errors }, { status: 400 }); } // themeColor goes into a