<commit_before>/**
 * Module dependencies.
 */

var express = require('express'),
    cookieParser = require('cookie-parser'),
    compress = require('compression'),
    session = require('express-session'),
    bodyParser = require('body-parser'),
    logger = require('morgan'),
    csrf = require('lusca').csrf(),
    methodOverride = require('method-override'),
    _ = require('lodash'),
    MongoStore = require('connect-mongo')({ session: session }),
    flash = require('express-flash'),
    path = require('path'),
    mongoose = require('mongoose'),
    passport = require('passport'),
    expressValidator = require('express-validator'),
    connectAssets = require('connect-assets'),
    ejs = require('ejs'),
    partials = require('express-partials'),
    i18n = require("i18n"),
    Site = require('./models/Site'),
    linkify = require("html-linkify"),
    app = express();

/**
 * App configuration settings
 */
var config = {
  app: require('./config/app'),
  secrets: require('./config/secrets')
};

/**
 * Connect to MongoDB.
 */
mongoose.connect(config.secrets.db);
mongoose.connection.on('error', function() {
  console.error('MongoDB Connection Error. Make sure MongoDB is running.');
});

/**
 * CSRF whitelist.
 */
var csrfExclude = [];

// i18n configuration
i18n.configure({
    // setup some locales - other locales default to en silently
    locales:['en', 'de'],
    defaultLocale: 'de',

    // set cookie name to parse locale settings from
    cookie: 'lang',

    // where to find json files
    directory: __dirname + '/locales',

    // whether to write new locale information to disk - defaults to true
    updateFiles: false,

    // what to use as the indentation unit - defaults to "\t"
    indent: "\t",
});

/**
 * Express configuration.
 */
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.engine('ejs', ejs.__express);
partials.register('.ejs', ejs);
app.use(partials());
app.use(compress());
app.use(connectAssets({
  paths: [path.join(__dirname, 'public/css'), path.join(__dirname, 'public/js')],
  helperContext: app.locals
}));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator());
app.use(methodOverride());
app.use(cookieParser());
app.use(session({
  resave: true,
  saveUninitialized: true,
  secret: config.secrets.sessionSecret,
  store: new MongoStore({
    url: config.secrets.db,
    auto_reconnect: true
  })
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function(req, res, next) {
  // CSRF protection.
  if (_.contains(csrfExclude, req.path)) return next();
  csrf(req, res, next);
});
app.use(function(req, res, next) {

  // Set default page title based on configured site name
  res.locals.title = Site.getName();

  // Expose site config object to all templates
  res.locals.site = Site;

  // Make user object available in all templates
  res.locals.user = req.user;

  // Expose path to views
  res.locals.path = req.path;
  
  // Expose linkify (to escape content while making hyperliks work) to all views
  res.locals.linkify = linkify;

  next();
});
app.use(function(req, res, next) {
  // Remember original destination before login.
  
  // Exceptions for paths we want to ignore
  // e.g. login pages, JavaScript files that make ajax calls
  var path = req.path.split('/')[1];
  if (/auth|login|css|images|logout|signup|js|fonts|favicon/i.test(path))
    return next();

  // Never return user to the account password reset page
  if (req.path == "/account/password")
    return next();
  
  // Never return the user to the vote forms (they are POST only)
  if (new RegExp('^' + '\/'+Site.getOptions().post.url+'\/(upvote|downvote|unvote)\/').test(req.path))
    return next();
    
  req.session.returnTo = req.path;
  next();
});

var hour = 3600000;
var day = hour * 24;
var week = day * 7;
app.use(express.static(path.join(__dirname, 'public'), { maxAge: week * 4 }));

/**
 * Route handlers
 */
var routes = {
  passport: require('./routes/passport'),
  user: require('./routes/user'),<commit_msg>Extending max session life to 4 weeks<commit_after>/**
 * Module dependencies.
 */

var express = require('express'),
    cookieParser = require('cookie-parser'),
    compress = require('compression'),
    session = require('express-session'),
    bodyParser = require('body-parser'),
    logger = require('morgan'),
    csrf = require('lusca').csrf(),
    methodOverride = require('method-override'),
    _ = require('lodash'),
    MongoStore = require('connect-mongo')({ session: session }),
    flash = require('express-flash'),
    path = require('path'),
    mongoose = require('mongoose'),
    passport = require('passport'),
    expressValidator = require('express-validator'),
    connectAssets = require('connect-assets'),
    ejs = require('ejs'),
    partials = require('express-partials'),
    i18n = require("i18n"),
    Site = require('./models/Site'),
    linkify = require("html-linkify"),
    app = express();

var hour = 3600000,
    day = hour * 24,
    week = day * 7;

/**
 * App configuration settings
 */
var config = {
  app: require('./config/app'),
  secrets: require('./config/secrets')
};

/**
 * Connect to MongoDB.
 */
mongoose.connect(config.secrets.db);
mongoose.connection.on('error', function() {
  console.error('MongoDB Connection Error. Make sure MongoDB is running.');
});

/**
 * CSRF whitelist.
 */
var csrfExclude = [];

// i18n configuration
i18n.configure({
    // setup some locales - other locales default to en silently
    locales:['en', 'de'],
    defaultLocale: 'de',

    // set cookie name to parse locale settings from
    cookie: 'lang',

    // where to find json files
    directory: __dirname + '/locales',

    // whether to write new locale information to disk - defaults to true
    updateFiles: false,

    // what to use as the indentation unit - defaults to "\t"
    indent: "\t",
});

/**
 * Express configuration.
 */
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.engine('ejs', ejs.__express);
partials.register('.ejs', ejs);
app.use(partials());
app.use(compress());
app.use(connectAssets({
  paths: [path.join(__dirname, 'public/css'), path.join(__dirname, 'public/js')],
  helperContext: app.locals
}));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator());
app.use(methodOverride());
app.use(cookieParser());
app.use(session({
  resave: true,
  saveUninitialized: true,
  secret: config.secrets.sessionSecret,
  store: new MongoStore({
    url: config.secrets.db,
    auto_reconnect: true
  }),
  cookie: {
    maxAge: 4 * week
  }
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function(req, res, next) {
  // CSRF protection.
  if (_.contains(csrfExclude, req.path)) return next();
  csrf(req, res, next);
});
app.use(function(req, res, next) {

  // Set default page title based on configured site name
  res.locals.title = Site.getName();

  // Expose site config object to all templates
  res.locals.site = Site;

  // Make user object available in all templates
  res.locals.user = req.user;

  // Expose path to views
  res.locals.path = req.path;
  
  // Expose linkify (to escape content while making hyperliks work) to all views
  res.locals.linkify = linkify;

  next();
});
app.use(function(req, res, next) {
  // Remember original destination before login.
  
  // Exceptions for paths we want to ignore
  // e.g. login pages, JavaScript files that make ajax calls
  var path = req.path.split('/')[1];
  if (/auth|login|css|images|logout|signup|js|fonts|favicon/i.test(path))
    return next();

  // Never return user to the account password reset page
  if (req.path == "/account/password")
    return next();
  
  // Never return the user to the vote forms (they are POST only)
  if (new RegExp('^' + '\/'+Site.getOptions().post.url+'\/(upvote|downvote|unvote)\/').test(req.path))
    return next();
    
  req.session.returnTo = req.path;
  next();
});

app.use(express.static(path.join(__dirname, 'public'), { maxAge: week * 4 }));

/**
 * Route handlers
 */
var routes = {
  passport: require('./routes/passport'),
  user: require('./routes/user'),
{'fraction_non_alphanumeric': 0.1701318759653083, 'fraction_numerical': 0.005940358797671379, 'mean_word_length': 3.7001675041876045, 'pattern_counts': {'":': 0, '<': 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': '3155703', 'n_tokens_mistral': 2720, 'n_tokens_neox': 2658, 'n_words': 689}