forked from sagarkarira/coronavirus-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
27 lines (22 loc) · 768 Bytes
/
app.js
File metadata and controls
27 lines (22 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const express = require('express');
const app = express();
const port = process.env.PORT || 3001;
const { getCountryTable } = require('./lib/byCountry');
const { getCompleteTable } = require('./lib/corona');
app.get('/', (req, res) => {
return getCompleteTable().then(result => {
return res.send(result);
}).catch(error => res.send(error));
});
app.get('/:country', (req, res) => {
let { country } = req.params;
if (!country || country === 'all') {
return getCompleteTable().then(result => {
return res.send(result);
}).catch(error => res.send(error));
}
return getCountryTable(country).then(result => {
return res.send(result);
}).catch(error => res.send(error));
});
app.listen(port, () => console.log(`Running on ${port}`));