From 8a1162e6686928502aa1b12f3692b6b142519f55 Mon Sep 17 00:00:00 2001
From: Erick Hitter <services@ethitter.com>
Date: Fri, 13 Jan 2017 20:45:44 -0800
Subject: [PATCH] Don't die if no location data is provided

---
 index.js | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index a95b999..fa58547 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'));
 });
-- 
GitLab