import { NextResponse } from "next/server"; // The crawl tick, fired by the PM2 cron (scripts/cron-digest.cjs) every 15 min. // Protected by the CRON_SECRET header so a random visitor cannot trigger a // crawl on demand (it costs feed fetches + og:image rescues + article // prefetches). export const maxDuration = 290; export async function POST(req) { const secret = req.headers.get("x-bama-cron"); if (secret !== (process.env.CRON_SECRET || "bama-cron")) { return NextResponse.json({ error: "unauthorized" }, { status: 401 }); } try { const { crawlOnce } = await import("../../../lib/crawl"); const crawl = await crawlOnce(); // Refresh the live "Who he is" bio from Wikipedia on the same tick // (well over "daily"). Best-effort: a Wikipedia hiccup must never // make the crawl report a failure or lose the news it already gathered. let bio = null; try { const { refreshBio } = await import("../../../lib/bio"); bio = await refreshBio(); } catch (e) { bio = { ok: false, error: String((e && e.message) || e).slice(0, 120) }; } return NextResponse.json({ ok: true, crawl, bio }); } catch (e) { return NextResponse.json({ ok: false, error: String((e && e.message) || e) }, { status: 500 }); } }