File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ const express = require ( 'express' ) ;
2
+ const get_data = require ( '../helpers/fetch-data' ) ;
3
+
4
+ const router = express . Router ( ) ;
5
+
6
+ const url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv' ;
7
+
8
+ router . get ( '/' , ( req , res ) => {
9
+ // fetch the data
10
+ get_data ( url )
11
+ . then ( response => res . json ( response ) ) ;
12
+ } ) ;
13
+
14
+ router . get ( '/:country' , ( req , res ) => {
15
+ // fetch the data
16
+ get_data ( url )
17
+ . then ( response => {
18
+
19
+ let countryData = { }
20
+ // loop through all the countries
21
+ response . forEach ( country => {
22
+ // for every country
23
+ // if there is Country/Region is equal to passed country
24
+ if ( country [ 'Country/Region' ] . toString ( ) . toLowerCase ( ) === req . params . country . toLowerCase ( ) ) {
25
+ countryData = country
26
+ }
27
+ } )
28
+ // send the country data back
29
+ res . send ( countryData ) ;
30
+ } ) . catch ( e => console . log ( e ) )
31
+ } ) ;
32
+
33
+ module . exports = router ;
You can’t perform that action at this time.
0 commit comments