var express = require('express');
var router = express.Router();
var apicache = require('apicache');

var cache = apicache.middleware;
if(process.env.REDIS_CACHE === '1'){
  cache = require('apicache')
           .options({ redisClient: require('redis').createClient() })
           .middleware;
}

var request = require('request-promise');

router.get('/', cache('5 seconds'), function(req, res, next) {
  res.json({ message: 'API is functioning.', time: + new Date() });
});

router.get('/buses', cache('1 minute'), function(req, res, next) {
  res.json({ message: 'Return a list of buses and times', time: + new Date() });
});

router.get('/weather', cache('5 minutes'), function(req, res, next) {
  request({
      uri: 'https://api.darksky.net/forecast/'+req.darksky_key+'/'+req.lat_long,
      json: true,
      gzip: true,
      resolveWithFullResponse: true
  }).then(function(response){
      console.log(response.request.uri);
      console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity'))
      res.json(response.body);
  }).catch(next);
});

module.exports = router;

@@ -331,24 +331,767 @@
 promise');%0A%0A
+// list of API urls for easy reference%0Avar api_ctabus = 'http://www.ctabustracker.com/bustime/api/';%0Avar api_darksky = 'https://api.darksky.net/forecast/';%0A%0Avar cta_bus_api = function(path, qs)%7B%0A    return function(req, res, next) %7B%0A      qs%5B'key'%5D = req.cta_key;%0A      qs%5B'format'%5D = 'json';%0A      qs%5B'locale'%5D = 'en';%0A      request(%7B%0A          uri: api_ctabus+req.cta_version+path,%0A          qs: qs,%0A          json: true,%0A          gzip: true,%0A          resolveWithFullResponse: true%0A      %7D).then(function(response)%7B%0A          console.log(response.request.uri);%0A          console.log('server encoded the data as: ' + (response.headers%5B'content-encoding'%5D %7C%7C 'identity'));%0A          res.json(response.body);%0A      %7D).catch(next);%0A    %7D;%0A%7D;%0A%0A
 router.get('
@@ -1307,18 +1307,16 @@
 ge: 
-'
+%22
 Return 
-a 
 list
@@ -1328,41 +1328,698 @@
 uses
- and times', time: + new Date() %7D
+%22 %7D);%0A%7D);%0A%0Arouter.get('/buses/time', cache('1 minute'), cta_bus_api('/gettime', %7B%7D));%0A%0Arouter.get('/buses/stops/:route_id/:route_direction', /*cache('24 hours'),*/ function(req, res, next) %7B%0A  var validDirections = %5B'Northbound', 'Eastbound', 'Southbound', 'Westbound'%5D;%0A  var routeDirection = req.params.route_direction.charAt(0).toUpperCase() + req.params.route_direction.slice(1);%0A  if(validDirections.indexOf(routeDirection) %3C 0)%7B%0A    console.error('Route direction must be one of ', validDirections);%0A    return next(new RangeError('Route direction must be one of ' + validDirections ));%0A  %7D%0A  cta_bus_api('/getstops', %7B'rt': req.params.route_id, 'dir': routeDirection%7D)(req, res, next
 );%0A%7D
@@ -2119,43 +2119,19 @@
 ri: 
-'https://
 api
-.
+_
 darksky
-.net/forecast/'
 +req
@@ -2408,16 +2408,17 @@
 ntity'))
+;
 %0A      r

add useful ctabus api function and list stops