/* MiddleWare */
/* pogoda z api.open-meteo.com */

const pogoda = async function(req, res, next) {
   if( req.url=='/api/pogoda'){
    const JSONreq = new Request("https://api.open-meteo.com/v1/forecast?latitude=52.41&longitude=16.93&current=temperature_2m,wind_speed_10m,precipitation,cloud_cover&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m");
    const JSONresp = await fetch(JSONreq);
    const data = await JSONresp.json();
    let d=data.hourly;
    var dt={ time:d.time.slice(0,24), 
             temp:d.temperature_2m.slice(0,24), 
             hum:d.relative_humidity_2m.slice(0,24), 
             wind:d.wind_speed_10m.slice(0,24)
            };
    req.d = dt;
    }
    next();
};

export default pogoda;