add routes

This commit is contained in:
Francesco Esposito 2019-08-15 23:23:00 +02:00
parent 61160e0d8a
commit dfa50e0636
1 changed files with 36 additions and 0 deletions

36
src/routes.js Normal file
View File

@ -0,0 +1,36 @@
import express from 'express';
import { getCurrentWeatherById, getForecastWeatherById } from './apiOWM';
const router = express.Router();
router.get('/current', (req, res) => {
getCurrentWeatherById(req.query.cityId)
.then((json) => res.send(json))
.catch((err) => {
const code = err.message;
if (code) {
res.status(code).send();
} else {
res.status(500).send(err.toString());
}
});
});
router.get('/forecast', (req, res) => {
getForecastWeatherById(req.query.cityId)
.then((json) => res.send(json))
.catch((err) => {
const code = err.message;
if (code) {
res.status(code).send();
} else {
res.status(500).send(err.toString());
}
});
});
export default router;