feat(hail-recon): enable live API — USE_MOCK off, KV dynamic import for graceful degradation
This commit is contained in:
+7
-6
@@ -2,12 +2,13 @@
|
||||
* 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.
|
||||
*
|
||||
* Requires Vercel KV to be connected for auto-trigger to work.
|
||||
* Without KV: always returns stormActive: false (manual Storm Mode still works).
|
||||
*
|
||||
* Response: { stormActive: boolean, event: StormEvent | null, checkedAt: number }
|
||||
*/
|
||||
|
||||
import { kv } from '@vercel/kv';
|
||||
|
||||
const STORM_ACTIVE_WINDOW_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||
const STORM_ACTIVE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
export default async function handler(req, res) {
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
@@ -17,6 +18,7 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const { kv } = await import('@vercel/kv');
|
||||
const event = await kv.get('lastStormEvent');
|
||||
|
||||
const stormActive = !!event &&
|
||||
@@ -28,9 +30,8 @@ export default async function handler(req, res) {
|
||||
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);
|
||||
} catch {
|
||||
// KV not configured — storm auto-trigger unavailable, manual toggle still works
|
||||
return res.status(200).json({
|
||||
stormActive: false,
|
||||
event: null,
|
||||
|
||||
Reference in New Issue
Block a user