@@ -8,6 +8,7 @@ const { getLiveUpdates } = require('./lib/reddit.js');
88
99const app = express ( ) ;
1010const port = process . env . PORT || 3001 ;
11+ const IS_CURL_RE = / \b c u r l \b / gim;
1112
1213function errorHandler ( error , res ) {
1314 console . error ( error ) ;
@@ -24,7 +25,7 @@ app.use((req, res, next) => {
2425} ) ;
2526
2627app . get ( '/' , ( req , res ) => {
27- const isCurl = req . headers [ 'user-agent' ] . match ( / \b c u r l \b / gim ) !== null ;
28+ const isCurl = IS_CURL_RE . test ( req . headers [ 'user-agent' ] ) ;
2829 const format = req . query . format ? req . query . format : '' ;
2930 const minimal = req . query . minimal === 'true' ;
3031 const emojis = req . query . emojis === 'true' ;
@@ -43,8 +44,9 @@ app.get('/', (req, res) => {
4344} ) ;
4445
4546app . get ( '/updates' , ( req , res ) => {
47+ const isCurl = IS_CURL_RE . test ( req . headers [ 'user-agent' ] ) ;
4648 const format = req . query . format ? req . query . format : '' ;
47- const isCurl = req . headers [ 'user-agent' ] . match ( / \b c u r l \b / gim ) !== null ;
49+
4850 if ( format . toLowerCase ( ) === 'json' ) {
4951 return getLiveUpdates ( { json : true , isCurl } ) . then ( result => {
5052 return res . json ( result ) ;
@@ -58,10 +60,11 @@ app.get('/updates', (req, res) => {
5860
5961app . get ( '/:country' , ( req , res ) => {
6062 const { country } = req . params ;
61- const isCurl = req . headers [ 'user-agent' ] . match ( / \b c u r l \b / gim ) !== null ;
63+ const isCurl = IS_CURL_RE . test ( req . headers [ 'user-agent' ] ) ;
6264 const format = req . query . format ? req . query . format : '' ;
6365 const minimal = req . query . minimal === 'true' ;
6466 const emojis = req . query . emojis === 'true' ;
67+
6568 if ( ! country || country . toUpperCase ( ) === 'ALL' ) {
6669 if ( format . toLowerCase ( ) === 'json' ) {
6770 return getJSONData ( ) . then ( result => {
0 commit comments