feat(hail-recon): Hail Recon integration — storm intel panel, hail history, auto storm mode, address monitoring
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Returns current storm status — polled by the frontend every 60 seconds.
|
||||
* Storm is considered "active" if an event was received within the last 24 hours.
|
||||
*
|
||||
* Response: { stormActive: boolean, event: StormEvent | null, checkedAt: number }
|
||||
*/
|
||||
|
||||
import { kv } from '@vercel/kv';
|
||||
|
||||
const STORM_ACTIVE_WINDOW_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||
|
||||
export default async function handler(req, res) {
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(405).json({ error: 'Method not allowed' });
|
||||
}
|
||||
|
||||
try {
|
||||
const event = await kv.get('lastStormEvent');
|
||||
|
||||
const stormActive = !!event &&
|
||||
typeof event.receivedAt === 'number' &&
|
||||
(Date.now() - event.receivedAt) < STORM_ACTIVE_WINDOW_MS;
|
||||
|
||||
return res.status(200).json({
|
||||
stormActive,
|
||||
event: stormActive ? event : null,
|
||||
checkedAt: Date.now(),
|
||||
});
|
||||
} catch (err) {
|
||||
// KV not configured (local dev without env vars) — return inactive
|
||||
console.warn('[hail-status] KV unavailable:', err.message);
|
||||
return res.status(200).json({
|
||||
stormActive: false,
|
||||
event: null,
|
||||
checkedAt: Date.now(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user