<commit_before>const express = require('express'),
    path = require('path'),
// favicon = require('serve-favicon'),
    logger = require('morgan'),
    cookieParser = require('cookie-parser'),
    bodyParser = require('body-parser'),
// mongoose = require('mongoose'),
    dbInitialize = require('./db/initialize'),
    routes = require('./routes'),
    app = express(),
    passport = require('passport'),
    auth = require('./auth'),
    envs = require('./config/envs'),
    expressSession = require('express-session');

let calledBefore = false;


module.exports = function(passedEnv) {
    if(!calledBefore) {
        let env = passedEnv || app.get('env');

        app.set('view engine', 'pug');
        app.set('views', path.join(__dirname, '/views'));

        // uncomment after placing your favicon in /public
        //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
        app.use(logger('dev'));
        app.use(bodyParser.json());
        app.use(bodyParser.urlencoded({ extended: true }));
        app.use(cookieParser());
        app.use(express.static(path.join(__dirname, '..', 'build')));
        app.use(function(req, res, next) {
            console.log('got request, env', env);
            console.log('secure:', req.secure);
            if(env === envs.PROD && !req.secure) {
                res.redirect('https://' + req.hostname + req.url); 
            } else {
                next();
            }
        });
        app.use(expressSession({
            secret: 'keyboard cat', // in prod this should be an ENV variable
            resave: false,
            saveUninitialized: false
        }));

        passport.serializeUser(auth.serializeUser);
        passport.deserializeUser(auth.deserializeUser);
        passport.use(auth.localStrategy);
        passport.use(auth.facebookStrategy);
        passport.use(auth.googleStrategy);
        app.use(passport.initialize());
        app.use(passport.session());

        app.use('/', routes);

        // catch 404 and forward to error handler
        // no need to send 404, let front end
        // app.use(function(req, res, next) {
        //   var err = new Error('Not Found');
        //   err.status = 404;
        //   next(err);
        // });
<commit_msg>okay, so adding more logging<commit_after>const express = require('express'),
    path = require('path'),
// favicon = require('serve-favicon'),
    logger = require('morgan'),
    cookieParser = require('cookie-parser'),
    bodyParser = require('body-parser'),
// mongoose = require('mongoose'),
    dbInitialize = require('./db/initialize'),
    routes = require('./routes'),
    app = express(),
    passport = require('passport'),
    auth = require('./auth'),
    envs = require('./config/envs'),
    expressSession = require('express-session');

let calledBefore = false;


module.exports = function(passedEnv) {
    if(!calledBefore) {
        let env = passedEnv || app.get('env');

        app.set('view engine', 'pug');
        app.set('views', path.join(__dirname, '/views'));

        // uncomment after placing your favicon in /public
        //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
        app.use(logger('dev'));
        app.use(bodyParser.json());
        app.use(bodyParser.urlencoded({ extended: true }));
        app.use(cookieParser());
        app.use(express.static(path.join(__dirname, '..', 'build')));
        app.use(function(req, res, next) {
            console.log('got request, env', env);
            console.log('secure:', req.secure);
            if(env === envs.PROD && !req.secure) {
                console.log('do redirect:', 'https://' + req.hostname + req.url);
                res.redirect('https://' + req.hostname + req.url); 
            } else {
                console.log('do next()');
                next();
            }
        });
        app.use(expressSession({
            secret: 'keyboard cat', // in prod this should be an ENV variable
            resave: false,
            saveUninitialized: false
        }));

        passport.serializeUser(auth.serializeUser);
        passport.deserializeUser(auth.deserializeUser);
        passport.use(auth.localStrategy);
        passport.use(auth.facebookStrategy);
        passport.use(auth.googleStrategy);
        app.use(passport.initialize());
        app.use(passport.session());

        app.use('/', routes);

        // catch 404 and forward to error handler
        // no need to send 404, let front end
        // app.use(function(req, res, next) {
        //   var err = new Error('Not Found');
        //   err.status = 404;
        //   next(err);
        // });

{'fraction_non_alphanumeric': 0.16570327552986513, 'fraction_numerical': 0.0038535645472061657, 'mean_word_length': 2.2580195258019526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, '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': '312446', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1314, 'n_words': 273}