add routes
This commit is contained in:
parent
61160e0d8a
commit
dfa50e0636
|
@ -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;
|
Loading…
Reference in New Issue