diff --git a/index.js b/index.js index 5bcb620c039aa38464aceef6ac143be665416af5..a95b99936b2d3caa1347eaa02688af79a4fb9cd4 100644 --- a/index.js +++ b/index.js @@ -2,26 +2,34 @@ var express = require('express'); var app = express(); var url = require('url'); var request = require('request'); +var config = require( './config.json' ); var format = ".json"; -var apikey = process.env.WU_ACCESS //WU API key; will be set in Heroku +var apikey = config.apikey; var bodyParser = require('body-parser'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); //use port is set in the environment variable, or 9001 if it isn’t set. -app.set('port', (process.env.PORT || 9001)); +app.set( 'port', ( config.port || 9001 ) ); //for testing that the app is running app.get('/', function(req, res){ - res.send('Running!!'); + var msg = 'Running!'; + + if ( ! apikey.length ) { + msg += ' Please set the API key.' + } + + res.send( msg ); }); //app.post is triggered when a POST request is sent to the URL ‘/post’ app.post('/post', function(req, res){ - //take a message from Slack slash command - var query = req.body.text + if ( ! apikey.length ) { + return res.sendStatus( 500 ); + } var parsed_url = url.format({ pathname: 'http://api.wunderground.com/api/' + apikey + '/conditions/q/' + req.body.text + format,