export async function wordle(req) { const { searchParams: sp } = new URL(req.url); const date = sp.get('date'); if (!date) { const today = new Date().toISOString().split('T')[0]; try { const res = await fetch(`https://www.nytimes.com/svc/wordle/v2/${today}.json`); if (!res.ok) throw new Error("not out yet"); const data = await res.json(); return { date: data.print_date || today, solution: data.solution || null, id: data.id || null, days_since_launch: data.days_since_launch || null, editor: data.editor || null }; } catch { return { error: "today's wordle not available yet, try again later", usage: "/wordle?date=2026-07-25" }; } } try { const res = await fetch(`https://www.nytimes.com/svc/wordle/v2/${date}.json`); if (!res.ok) throw new Error("not found"); const data = await res.json(); return { date: data.print_date || date, solution: data.solution || null, id: data.id || null, days_since_launch: data.days_since_launch || null, editor: data.editor || null }; } catch { return { error: `no wordle for ${date}` }; } }