SilvrAPI/server/routes/weather.js
2020-02-03 14:45:22 +00:00

98 lines
1.7 KiB
JavaScript

var router = require('express-promise-router')();
const weather = require('../lib/weather');
const logger = require('log4js').getLogger('simpleWeather');
logger.level = 'debug';
/*
OpenWeather:
/ow/forecast
/ow/fullforecast
DarkSkies
/ds/forecast
/ds/fullforecast
*/
router.get('/ow/forecast', async (req, res, next) => {
if (req.query.hasOwnProperty('ll')) {
const ll = req.query.ll;
const weatherData = await weather.doGetOpenWeather(ll);
res.send(weatherData);
}
else {
// throw new Error('Weather: LL missing');
logger.warn('FS: LL missing');
res.status(500).send('LL Missing');
}
});
router.get('/ow/fullforecast', async (req, res, next) => {
if (req.query.hasOwnProperty('ll')) {
const ll = req.query.ll;
const weatherData = await weather.doGetOpenWeatherForecast(ll);
res.send(weatherData);
}
else {
// throw new Error('Weather: LL missing');
logger.warn('FS: LL missing');
res.status(500).send('LL Missing');
}
});
router.get('/ds/forecast', async (req, res, next) => {
if (req.query.hasOwnProperty('ll')) {
const ll = req.query.ll;
const weatherData = await weather.doGetDarkSkyWeather(ll);
res.send(weatherData);
}
else {
// throw new Error('Weather: LL missing');
logger.warn('FS: LL missing');
res.status(500).send('LL Missing');
}
});
router.get('/ds/fullforecast', async (req, res, next) => {
if (req.query.hasOwnProperty('ll')) {
const ll = req.query.ll;
const weatherData = await weather.doGetFullForcast(ll);
res.send(weatherData);
}
else {
// throw new Error('Weather: LL missing');
logger.warn('FS: LL missing');
res.status(500).send('LL Missing');
}
});
module.exports = router;