Build an API route that returns nearby mental health resources so users in crisis always know where to turn. `GET /api/resources?lat=X&lng=Y&type=crisis|therapy|support&radius=25` Data sources (in priority order): 1. SAMHSA Treatment Locator API (free, no key required) — for `therapy` and `support` types 2. A seeded `crisis_hotlines` database table (always available offline) — for `crisis` type 3. Hardcoded national fallbacks — always included regardless of type Response: ```typescript { resources: Resource[], // sorted by distance ascending source: 'live' | 'cached' | 'fallback', fetchedAt: string } ``` Caching: - Cache SAMHSA results in Redis for 24 hours keyed by `resources:{lat_2dp}:{lng_2dp}:{type}` - On Redis miss or Redis unavailable, fetch live and cache - On SAMHSA API error, return cached result or hardcoded fallbacks Rate limit: 20 req/min per IP using the existing `lib/rate-limit.ts` utility. Write unit tests covering: cache hit, SAMHSA live fetch, SAMHSA failure with fallback, missing lat/lng (400 error).
No contributions yet.