diff --git a/index.js b/index.js index a95b99936b2d3caa1347eaa02688af79a4fb9cd4..fa58547ee871f765ed04986931d52fb4073ab5bd 100644 --- a/index.js +++ b/index.js @@ -27,10 +27,16 @@ app.get('/', function(req, res){ //app.post is triggered when a POST request is sent to the URL ‘/post’ app.post('/post', function(req, res){ + // Can't proceed without an API key if ( ! apikey.length ) { return res.sendStatus( 500 ); } + // Don't bother if there's nothing to look up + if ( 'undefined' === typeof req.body.text || ! req.body.text.length ) { + return res.sendStatus( 400 ); + } + var parsed_url = url.format({ pathname: 'http://api.wunderground.com/api/' + apikey + '/conditions/q/' + req.body.text + format, }); @@ -63,5 +69,5 @@ app.post('/post', function(req, res){ //tells Node which port to listen on app.listen(app.get('port'), function() { - console.log('Node app is running on port', app.get('port')); + console.log('Weather on the Slash is running on port', app.get('port')); });