<commit_before>/*
 * lib/server.js
 *
 *
 * Copyright (C) 2014  <NAME> <<EMAIL>>
 *
 * License in LICENSE file at the root of the repository.
 *
 */


var path = require('path');

var express = require('express'),
    favicon = require('static-favicon'),
    logger = require('morgan'),
    cookieParser = require('cookie-parser'),
    session = require('express-session'),
    RedisStore = require('connect-redis')(session),
    bodyParser = require('body-parser'),
    multer = require('multer');

var passport = require('passport'),
    Strategy = require('passport-local').Strategy,
    cache = require('./cache'),
    store = require('./store'),
    auth = require('./auth');



passport.serializeUser(function(user, done) {
    done(null, user.id);
});

passport.deserializeUser(function(id, done) {
    cache.client()
        .get('user', id)
        .then(function(user){
            done(null, user);
        })
        .catch(function(err){
            done({
                error: 'cannot find user'
            });
        });
});

passport.use(new Strategy(auth.verify));

module.exports = function(config){

    config = config || {};
    var app = express();

    // view engine setup
    app.set('views', config.views || path.join(__dirname, '../views'));
    app.set('view engine', config.viewEngine || 'jade');

    app.use(favicon());
    app.use(logger('dev'));
    app.use(bodyParser.json({
        'limit': config.bodyParserLimit || '400kb'
    }));
    app.use(bodyParser.urlencoded());
    app.use(cookieParser());
    app.use(express.static(config.static || path.join(__dirname, '../public')));
    app.use(multer({
        'dest': config.uploadDir || path.join(__dirname, '../uploads'),
        'putSingleFilesInArray': true
    }));
    
    if (!('session' in config)) {
        throw (new Error('We really need session support, update your config please'));
    }
    var sessionConfig = {
        'secret': config.session.secret || 'xxxxxxxxx',
        resave: false,<commit_msg>exit rather than throw on lack of session config<commit_after>/*
 * lib/server.js
 *
 *
 * Copyright (C) 2014  <NAME> <<EMAIL>>
 *
 * License in LICENSE file at the root of the repository.
 *
 */


var path = require('path');

var express = require('express'),
    favicon = require('static-favicon'),
    logger = require('morgan'),
    cookieParser = require('cookie-parser'),
    session = require('express-session'),
    RedisStore = require('connect-redis')(session),
    bodyParser = require('body-parser'),
    multer = require('multer');

var passport = require('passport'),
    Strategy = require('passport-local').Strategy,
    cache = require('./cache'),
    store = require('./store'),
    auth = require('./auth');



passport.serializeUser(function(user, done) {
    done(null, user.id);
});

passport.deserializeUser(function(id, done) {
    cache.client()
        .get('user', id)
        .then(function(user){
            done(null, user);
        })
        .catch(function(err){
            done({
                error: 'cannot find user'
            });
        });
});

passport.use(new Strategy(auth.verify));

module.exports = function(config){

    config = config || {};
    var app = express();

    // view engine setup
    app.set('views', config.views || path.join(__dirname, '../views'));
    app.set('view engine', config.viewEngine || 'jade');

    app.use(favicon());
    app.use(logger('dev'));
    app.use(bodyParser.json({
        'limit': config.bodyParserLimit || '400kb'
    }));
    app.use(bodyParser.urlencoded());
    app.use(cookieParser());
    app.use(express.static(config.static || path.join(__dirname, '../public')));
    app.use(multer({
        'dest': config.uploadDir || path.join(__dirname, '../uploads'),
        'putSingleFilesInArray': true
    }));

    if (!('session' in config)) {
        console.error('We really need session support, update your config please');
        process.exit(1);
    }
    var sessionConfig = {
        'secret': config.session.secret || '<KEY>',
        resave: false,
{'fraction_non_alphanumeric': 0.17772861356932154, 'fraction_numerical': 0.003687315634218289, 'mean_word_length': 2.8605313092979125, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '709554', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1191, 'n_words': 260}