<commit_before>'use strict';

var sf = require('sf');
var ejs = require('ejs');
var fs = require('fs');
var path = require('path');
var redis = require('redis');
var express = require('express');
var browserify = require('browserify');

var viewsPath = path.join(__dirname, '../web/views');
var staticPath = path.join(__dirname, '../web/static');
var redisConnection = null;

module.exports = function (webPort, _redisConnection) {
  redisConnection = _redisConnection;

  var app = express.createServer();
  app.dynamicHelpers({
    sf: function (req, res) {
      return sf;
    },
    isLoggedIn: function (req, res) {
      return function () { return redisConnection ? true : false; };
    },
    getFlashes: function (req, res) {
      return function () { return req.flash(); }
    }
  });
  app.login = login;
  app.logout = logout;
  app.layoutFilename = path.join(__dirname, '../web/views/layout.ejs');
  app.set('views', viewsPath);
  app.set('view engine', 'ejs');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.query());
  app.use(express.cookieParser());
  app.use(express.session({ secret: "rediscommander" }));
  app.use(browserify(path.join(__dirname, 'browserifyEntry.js')));
  app.use(addConnectionToRequest);
  app.use(app.router);
  app.use(express.static(staticPath));
  require('./routes')(app);

  app.listen(webPort);

  console.log("listening on ", webPort);
};

function logout() {
  redisConnection = null;
}

function login(hostname, port, callback) {
  console.log('connecting... ', hostname, port);
  redisConnection = redis.createClient(port, hostname);
  redisConnection.on("error", function (err) {
    console.error("Redis error", err.stack);
    if (callback) {
      callback(err);
      callback = null;
    }
  });
  redisConnection.on("connect", callback);
}

function addConnectionToRequest(req, resp, next) {
  req.redisConnection = redisConnection;
  return next();
}<commit_msg>Redis connection will only be attempted 5 times.<commit_after>'use strict';

var sf = require('sf');
var ejs = require('ejs');
var fs = require('fs');
var path = require('path');
var redis = require('redis');
var express = require('express');
var browserify = require('browserify');

var viewsPath = path.join(__dirname, '../web/views');
var staticPath = path.join(__dirname, '../web/static');
var redisConnection = null;

module.exports = function (webPort, _redisConnection) {
  redisConnection = _redisConnection;

  var app = express.createServer();
  app.dynamicHelpers({
    sf: function (req, res) {
      return sf;
    },
    isLoggedIn: function (req, res) {
      return function () { return redisConnection ? true : false; };
    },
    getFlashes: function (req, res) {
      return function () { return req.flash(); }
    }
  });
  app.login = login;
  app.logout = logout;
  app.layoutFilename = path.join(__dirname, '../web/views/layout.ejs');
  app.set('views', viewsPath);
  app.set('view engine', 'ejs');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.query());
  app.use(express.cookieParser());
  app.use(express.session({ secret: "rediscommander" }));
  app.use(browserify(path.join(__dirname, 'browserifyEntry.js')));
  app.use(addConnectionToRequest);
  app.use(app.router);
  app.use(express.static(staticPath));
  require('./routes')(app);

  app.listen(webPort);

  console.log("listening on ", webPort);
};

function logout() {
  redisConnection = null;
}

function login(hostname, port, callback) {
  console.log('connecting... ', hostname, port);
  redisConnection = redis.createClient(port, hostname, {"max_attempts":5});
  redisConnection.on("error", function (err) {
    console.error("Redis error", err.stack);
    if (callback) {
      callback(err);
      callback = null;
    }
  });
  redisConnection.on("connect", callback);
}

function addConnectionToRequest(req, resp, next) {
  req.redisConnection = redisConnection;
  return next();
}
{'fraction_non_alphanumeric': 0.16955538809344387, 'fraction_numerical': 0.0005023863350916855, 'mean_word_length': 4.281167108753316, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2033830', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1269, 'n_words': 272}