import { NextResponse } from "next/server"; import { getSupabaseAdmin } from "@/lib/admin"; import { supabase } from "@/lib/supabase"; export async function POST(request: Request) { try { const { websiteId } = await request.json(); // Create a new scan const { data: scan, error: scanError } = await supabase .from("scans") .insert([ { website_id: websiteId, status: "pending", }, ]) .select() .single(); if (scanError) throw scanError; // Trigger the analysis process const response = await fetch("/api/analyze", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ websiteId, scanId: scan.id, }), }); if (!response.ok) { throw new Error("Failed to start analysis"); } return NextResponse.json({ success: true, scanId: scan.id }); } catch (error) { console.error("Monitor start error:", error); return NextResponse.json( { error: "Failed to start monitoring" }, { status: 500 }, ); } }