Design: Proxy OpenWeather API through Cloudflare Worker
Problem
The OpenWeather API key is exposed client-side via PUBLIC_OPENWEATHER_KEY. Move the call behind the Cloudflare Worker, matching the pattern used for IP Registry geolocation.
Design
API (Cloudflare Worker)
New endpoint: GET /weather?lat={lat}&lon={lon}&units={units}
handleWeather()inapi.tsvalidates query params, callshttps://api.openweathermap.org/data/2.5/weatherwithenv.OPENWEATHER_KEY- Returns normalized response:
{"main": "Clouds","description": "overcast clouds","icon": "04d","temp": 72,"sunrise": 1709553600,"sunset": 1709594400}
- Route added in
index.tsfollowing existing pattern - New secret
OPENWEATHER_KEYadded toEnvtype and.dev.vars.example
App (Frontend)
fetchWeather()inapi.tscalls${apiUrl}/weather?lat=...&lon=...&units=...instead of OpenWeather directly- Remove
PUBLIC_OPENWEATHER_KEYfrom.env.exampleand all references - Remove
owKeyparameter threading throughLiveWindow.ts→fetchWeather()
Unchanged
- Rate limiting (client-side, 30-min interval)
- Weather data consumers (WeatherLayer, InfoPanel)
- CORS config