Skip to content
Snippets Groups Projects
Verified Commit 558c6278 authored by Erick Hitter's avatar Erick Hitter
Browse files

Move to a config file to simplify using this with pm2 and the like

parent ee061ab1
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment