50e25e3ee8
Rename subdirectories for a cleaner single-repo layout: - website-monitoring-backend/ → backend/ - website-monitoring-frontend/ → frontend/ - website-monitoring-devops/ → devops/ Update all references in package.json scripts, CI workflows, docker-compose, pre-commit hooks, and documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
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 },
|
|
);
|
|
}
|
|
}
|