| 1 | |
| 2 | import { NextResponse } from 'next/server'; |
| 3 | import { stealthFetch } from '@/lib/stealthFetch'; |
| 4 | |
| 5 | /** |
| 6 | * OSIRIS — Severe Weather & Anomalies API |
| 7 | * Fetches active natural events from NASA EONET (Earth Observatory Natural Event Tracker) |
| 8 | * Tracks: Severe Storms (Hurricanes/Typhoons), Volcanoes, Sea Ice |
| 9 | */ |
| 10 | |
| 11 | export async function GET() { |
| 12 | try { |
| 13 | // Fetch currently open events from EONET v3 |
| 14 | const res = await stealthFetch('https://eonet.gsfc.nasa.gov/api/v3/events?status=open&limit=100', { |
| 15 | signal: AbortSignal.timeout(10000), |
| 16 | }); |
| 17 | |
| 18 | if (!res.ok) throw new Error(`NASA EONET API returned ${res.status}`); |
| 19 | |
| 20 | const data = await res.json(); |
| 21 | const events = []; |
| 22 | |
| 23 | for (const event of data.events || []) { |
| 24 | // Get the most recent geometry point |
| 25 | const geom = event.geometry && event.geometry.length > 0 ? event.geometry[event.geometry.length - 1] : null; |
| 26 | if (!geom || geom.type !== 'Point') continue; // Skip polygons for now |
| 27 | |
| 28 | const category = event.categories?.[0]?.id || 'unknown'; |
| 29 | |
| 30 | // We already track wildfires via FIRMS, so we skip EONET wildfires |
| 31 | if (category === 'wildfires') continue; |
| 32 | |
| 33 | let typeLabel = 'Event'; |
| 34 | let icon = 'alert'; |
| 35 | let severity = 'low'; |
| 36 | |
| 37 | if (category === 'severeStorms') { |
| 38 | typeLabel = 'Severe Storm'; |
| 39 | icon = 'cyclone'; |
| 40 | severity = 'high'; |
| 41 | } else if (category === 'volcanoes') { |
| 42 | typeLabel = 'Volcano Eruption'; |
| 43 | icon = 'volcano'; |
| 44 | severity = 'high'; |
| 45 | } else if (category === 'seaIce') { |
| 46 | typeLabel = 'Iceberg / Sea Ice'; |
| 47 | icon = 'ice'; |
| 48 | severity = 'medium'; |
| 49 | } else if (category === 'earthquakes') { |
| 50 | continue; // Handled by USGS |
| 51 | } else { |
| 52 | typeLabel = event.categories?.[0]?.title || 'Anomaly'; |
| 53 | } |
| 54 | |
| 55 | events.push({ |
| 56 | id: event.id, |
| 57 | title: event.title, |
| 58 | category: category, |
| 59 | type: typeLabel, |
| 60 | icon: icon, |
| 61 | severity: severity, |
| 62 | lat: geom.coordinates[1], |
| 63 | lng: geom.coordinates[0], |
| 64 | date: geom.date, |
| 65 | source: event.sources?.[0]?.url || 'NASA EONET', |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | return NextResponse.json({ |
| 70 | events, |
| 71 | total: events.length, |
| 72 | timestamp: new Date().toISOString(), |
| 73 | }); |
| 74 | |
| 75 | } catch (error) { |
| 76 | console.error('Weather API error:', error); |
| 77 | return NextResponse.json({ events: [], error: 'Failed to fetch NASA EONET data' }, { status: 500 }); |
| 78 | } |
| 79 | } |
| 80 | |