<commit_before>'use strict';
module.exports = function(app, db) {

  app.route('/latest')
    // Retrieve most recent searches
    .get(handleGet);

  app.get('/:query?offset=10', handlePost);

  function handleGet (req, res, db) {
      // Get and display latest searches
      var objArr;
      res.send(objArr);
  }
  
  function handlePost (req, res, db) {
      // Get images and save query and date.
      var results;
      res.send(results);
  }





<commit_msg>Trying to connect to db<commit_after>'use strict';
module.exports = function(app, db) {

  app.route('/latest')
    // Retrieve most recent searches
    .get(handleGet);

  app.get('/:query', handlePost);

  function handleGet (req, res, db) {
      // Get and display latest searches
      getHistory(db, res);
  }
  
  function handlePost (req, res, db) {
      // Get images and save query and date.
      var ip = req.headers['x-forwarded-for'] || 
                 req.connection.remoteAddress || 
                 req.socket.remoteAddress ||
                 req.connection.socket.remoteAddress;
      var query = req.params.query;
      var size = req.query;
      var url = 'https://ajax.googleapis.com/ajax/services/search/imagesv=1.0&q=' + query + '&userip=' + ip + '&rsz=' + size.offset;
      var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
              var results = JSON.parse(xmlhttp.responseText);
              res.send(results);
              save(results, db);
          }
      };
      xmlhttp.open("GET", url, true);
      xmlhttp.send();
  }
  
  function save(obj, db) {
    // Save object into db.
    var searches = db.collection('searches');
    searches.save(obj, function(err, result) {
      if (err) throw err;
      console.log('Saved ' + result);
    });
  }
  
  function getHistory(db, res) {
    // Check to see if the site is already there
    var searches = db.collection('searches');
    // get the url
    searches.find(function(err, result) {
      if (err) throw err;
      // object of the url
      if (result) {
        // we have a result
        console.log('Found ' + result);
        res.send(result);
      } else {
        // we don't
        res.send('No history Found');
      }
    });
  }






{'fraction_non_alphanumeric': 0.13689195006457167, 'fraction_numerical': 0.0034438226431338786, 'mean_word_length': 2.111111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7441957', 'n_tokens_mistral': 735, 'n_tokens_neox': 706, 'n_words': 185}