'use strict';

/* ========================== VENDOR DEPENDENCIES ========================== */

const express  = require('express');
//const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const dotenv   = require('dotenv').config();
const app      = express();


/* =========================== LOCAL DEPENDENCIES ========================== */

const pengo    = require('./app/pengo');


/* ============================= GLOBAL CONFIG ============================= */

const PORT = process.env.PORT || 3000;
const url = process.env.MONGOLAB_URI;

//app.use(bodyParser.json());
//app.use(bodyParser.urlencoded({ extended: true }));


/* ============================ DATABASE CONNECT =========================== */

mongoose.connect(url);

const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
	console.log('Db connected successfully');
});


/* ================================= ROUTES ================================ */

app.use(express.static('images'); // for fetching rant image

app.get('/',function(req,res){
  res.send('In root directory');
});

app.get('/pengo', function(req, res) {
  pengo.handleCommand(req, res)
});

// user enters 'path/48' to get quote #48
// app.get('/:quote_id', function(req,res){
//   getQuote.byID(req.params.quote_id, function(err, result) {
//     if (err) console.error(err);
//     res.send("Quote #" + req.params.quote_id + " is:<br>" + result);
//   });
// });


/* ================================ RUN APP ================================ */

app.listen(PORT, function(){
	console.log('Server is listening to %d port in %s mode',PORT,app.settings.env);
});

@@ -1114,82 +1114,424 @@
 %7B%0A  
-res.send('In root directory');%0A%7D);%0A%0Aapp.get('/pengo', function(req, res) %7B
+// req.body is for testing.  Dump when Pengo goes live.%0A  req.body = %0A  %7B%0A    %22token%22 : %22gIkuvaNzQIHg97ATvDxqgjtO%22,%0A    %22team_id%22 : %22T0001%22,%0A    %22team_domain%22 : %22example%22,%0A    %22channel_id%22 : %22C2147483705%22,%0A    %22channel_name%22 : %22jones%22,%0A    %22user_id%22 : %22U2147483697%22,%0A    %22user_name%22 : %22peterjmartinson%22,%0A    %22command%22 : %22/pengo%22,%0A    %22text%22 : %22%22,%0A    %22response_url%22 : %22https://hooks.slack.com/commands/1234/5678%22%0A  %7D
 %0A  p
@@ -1562,59 +1562,15 @@
 res)
+;
 %0A%7D);%0A%0A
-// user enters 'path/48' to get quote #48%0A// 
 app.
@@ -1610,26 +1610,19 @@
 s)%7B%0A
-//   getQuote.byID
+console.log
 (req
@@ -1641,97 +1641,275 @@
 e_id
-, function(err, result) %7B%0A//     if (err) console.error(err);%0A//     res.send(%22Quote #%22 +
+);%0Areq.body = %0A%7B%0A  %22token%22 : %22gIkuvaNzQIHg97ATvDxqgjtO%22,%0A  %22team_id%22 : %22T0001%22,%0A  %22team_domain%22 : %22example%22,%0A  %22channel_id%22 : %22C2147483705%22,%0A  %22channel_name%22 : %22jones%22,%0A  %22user_id%22 : %22U2147483697%22,%0A  %22user_name%22 : %22peterjmartinson%22,%0A  %22command%22 : %22/pengo%22,%0A  %22text%22 :
  req
@@ -1928,51 +1928,142 @@
 e_id
- + %22 is:%3Cbr%3E%22 + result);%0A//   %7D);%0A// 
+,%0A  %22response_url%22 : %22https://hooks.slack.com/commands/1234/5678%22%0A%7D%0A  // console.log(req.body);%0A  pengo.handleCommand(req, res);%0A
 %7D);%0A%0A
-%0A
 /* =

Fix routes in server.js