From de9cb41d8b6b35cfa385f0666ac570f7cdb089a8 Mon Sep 17 00:00:00 2001 From: Nate Emmert Date: Wed, 2 Sep 2026 08:37:14 -0400 Subject: [PATCH] Log NWS alerts to history regardless of push subscribers The alert history log was only populated inside the subscriber loop, so it stayed empty when no push subscriptions existed. Now the cron always checks and logs active NWS alerts for the dashboard location before the subscriber early-return. Co-Authored-By: Claude Sonnet 4.6 --- app/server.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/server.js b/app/server.js index 303ce09..3789e56 100644 --- a/app/server.js +++ b/app/server.js @@ -734,6 +734,22 @@ async function alertWatcherCron() { } catch {} } + // ── Log NWS alerts for the dashboard location regardless of subscribers ─────── + const dashLat = dashAuth?.stationLat; + const dashLon = dashAuth?.stationLon; + if (dashLat != null) { + const dashAlertData = await fetch(`${base}/api/alerts?lat=${dashLat}&lon=${dashLon}`) + .then(r => r.json()).catch(() => ({ features: [] })); + for (const a of dashAlertData.features || []) { + const alertId = a.id || a.properties?.id; + if (alertId && !loggedAlertIds.has(alertId)) { + loggedAlertIds.add(alertId); + const p = a.properties || {}; + recordAlertLog({ type: 'nws', alertId, event: p.event, headline: p.headline, effective: p.effective, expires: p.expires, lat: dashLat, lon: dashLon }); + } + } + } + if (!pushSubscriptions.length) return; for (const sub of [...pushSubscriptions]) {