
var express = require('express');
var app = express();
var request = require('request');
var Yelp = require('yelp');
var path = require('path');

require('dotenv').config();

app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});

app.use(express.static(__dirname + '/'));
app.use('/bower_components',  express.static(__dirname + '/bower_components'));

var yelp = new Yelp({
    consumer_key: process.env.YELP_CONSUMER_KEY,
    consumer_secret: process.env.YELP_CONSUMER_SECRET,
    token: process.env.YELP_TOKEN,
    token_secret: process.env.YELP_TOKEN_SECRET,
});

app.get('/', function (req, res) {
    res.sendFile(path.join(__dirname+'/index.html'));
});

app.get('/search', function (req, res) {
    var results = {
        success: true,
        error: null,
        locations: []
    };

    var params = {
        term: 'pizza'
    };

    if (req.query.city) {
        params.location = req.query.city;
    } else {
        params.ll = req.query.ll;
    }

    yelp.search(params).then(function (response) {
        var businesses = response.businesses;

        for (var i = 0; i < businesses.length; i++) {
            results.locations.push(businesses[i]);
        }

        res.send(results);
    }).catch(function (err) {
        results.success = true,
        results.error = error;
        res.send(results);
    });
});

app.listen(process.env.PORT || 5000, function () {
    console.log('Example app listening on port 5000!');
});

@@ -1,12 +1,14 @@
 %0A
-var
+const
  express
@@ -30,19 +30,21 @@
 ress');%0A
-var
+const
  app = e
@@ -53,19 +53,21 @@
 ress();%0A
-var
+const
  request
@@ -89,19 +89,21 @@
 uest');%0A
-var
+const
  Yelp = 
@@ -119,19 +119,21 @@
 yelp');%0A
-var
+const
  path = 
@@ -187,24 +187,17 @@
 app.use(
-function
+ 
 (req, re
@@ -204,16 +204,19 @@
 s, next)
+ =%3E
  %7B%0A    r
@@ -500,19 +500,21 @@
 ts'));%0A%0A
-var
+const
  yelp = 
@@ -729,25 +729,16 @@
 get('/',
- function
  (req, r
@@ -736,24 +736,27 @@
 , (req, res)
+ =%3E
  %7B%0A    res.s
@@ -823,25 +823,16 @@
 search',
- function
  (req, r
@@ -838,18 +838,21 @@
 res)
+ =%3E
  %7B%0A    
-var
+let
  res
@@ -938,19 +938,21 @@
 %7D;%0A%0A    
-var
+const
  params 
@@ -1140,76 +1140,22 @@
 hen(
-function (response) %7B%0A        var businesses = response.businesses;%0A
+ response =%3E %7B
 %0A   
@@ -1168,11 +1168,11 @@
 or (
-var
+let
  i =
@@ -1179,16 +1179,25 @@
  0; i %3C 
+response.
 business
@@ -1249,16 +1249,25 @@
 ns.push(
+response.
 business
@@ -1329,22 +1329,15 @@
 tch(
-function (err)
+ err =%3E
  %7B%0A 
@@ -1479,19 +1479,13 @@
 00, 
-function ()
+() =%3E
  %7B%0A 

converting to ES6