@@ -9,6 +9,7 @@ const port = process.env.PORT || 3001;
99const { getCountryTable, getJSONData, getJSONDataForCountry } = require ( './lib/byCountry' ) ;
1010const { getCompleteTable } = require ( './lib/corona' ) ;
1111const { lookupCountry } = require ( './lib/helpers' ) ;
12+ const { getLiveUpdates } = require ( './lib/reddit.js' ) ;
1213
1314
1415function errorHandler ( error , res ) {
@@ -26,36 +27,39 @@ app.use((req, res, next) => {
2627} ) ;
2728
2829
29- + app . get ( '/updates' , ( req , res ) => {
30- const format = req . query . format ? req . query . format : '' ;
31- if ( format . toLowerCase ( ) === 'json' ) {
32- return getLiveUpdates ( true ) . then ( result => {
33- return res . json ( result ) ;
34- } ) . catch ( error => errorHandler ( error , res ) ) ;
35- }
36- return getLiveUpdates ( false ) . then ( result => {
37- return res . send ( result ) ;
38- } ) . catch ( error => errorHandler ( error , res ) ) ;
39- } ) ;
4030
4131app . get ( '/' , ( req , res ) => {
4232 const isCurl = req . headers [ 'user-agent' ] . match ( / \b c u r l \b / gmi) !== null ;
4333 const format = req . query . format ? req . query . format : '' ;
4434 const minimal = req . query . minimal === 'true' ? true : false ;
4535 const emojis = req . query . emojis === 'true' ? true : false ;
36+ const top = req . query . top ? Number ( req . query . top ) : 1000 ;
4637
4738 if ( format . toLowerCase ( ) === 'json' ) {
4839 return getJSONData ( ) . then ( result => {
4940 return res . json ( result ) ;
5041 } ) . catch ( error => errorHandler ( error , res ) ) ;
5142 }
5243
53- return getCompleteTable ( { isCurl, emojis, minimal } )
44+ return getCompleteTable ( { isCurl, emojis, minimal, top } )
5445 . then ( result => {
5546 return res . send ( result ) ;
5647 } ) . catch ( error => errorHandler ( error , res ) ) ;
5748} ) ;
5849
50+ app . get ( '/updates' , ( req , res ) => {
51+ const format = req . query . format ? req . query . format : '' ;
52+ const isCurl = req . headers [ 'user-agent' ] . match ( / \b c u r l \b / gmi) !== null ;
53+ if ( format . toLowerCase ( ) === 'json' ) {
54+ return getLiveUpdates ( { json : true , isCurl } ) . then ( result => {
55+ return res . json ( result ) ;
56+ } ) . catch ( error => errorHandler ( error , res ) ) ;
57+ }
58+ return getLiveUpdates ( { json : false , isCurl } ) . then ( result => {
59+ return res . send ( result ) ;
60+ } ) . catch ( error => errorHandler ( error , res ) ) ;
61+ } ) ;
62+
5963app . get ( '/:country' , ( req , res ) => {
6064 const { country } = req . params ;
6165 const isCurl = req . headers [ 'user-agent' ] . match ( / \b c u r l \b / gmi) !== null ;
0 commit comments