<commit_before>'use strict';

//var connect = require('connect');
var underscore = require('underscore');
var path = require('path');
var redirectAugumentMiddleware = require('./server/redirectAugmentMiddleware').redirectAugmentMiddleware;
var loginRedirectMiddleware = require('./server/loginRedirectMiddleware').loginRedirectMiddleware;
var loginApplicationMiddleware = require('./server/loginApplicationMiddleware').loginApplicationMiddleware;
var loggedApplicationMiddleware = require('./server/loggedApplicationMiddleware').loggedApplicationMiddleware;
var passport = require('passport');
var serverConfig = {
  app: require('./bower.json').appPath || 'app',
  dist: 'dist',
  server: 'server',
  serverTest: 'server_test'
};
serverConfig.appStatic = serverConfig.app + path.sep + 'static';
serverConfig.distStatic = serverConfig.dist + path.sep + 'static';


var mountFolder = function (connect, dir) {
  return connect.static(path.resolve(dir));
};

function createCommonMiddlewares(connect) {
  return [
    connect.logger(),
    connect.bodyParser(),
    connect.cookieParser(),
    connect.query(),
    connect.session({secret: 'secret'}),
    passport.initialize(),
    passport.session(),
    redirectAugumentMiddleware
  ];
}

function getMiddlewares (connect, staticFolders, applicationDirectory){
  var result = createCommonMiddlewares(connect);

  underscore.each(staticFolders, function (staticFolder) {
    result.push(mountFolder(connect, staticFolder));
  });

  result = result.concat([
    loginRedirectMiddleware,
    loginApplicationMiddleware(applicationDirectory),
    loggedApplicationMiddleware(applicationDirectory)
  ]);

  return result;
}


exports.serverConfig = serverConfig;

exports.getMiddlewares = getMiddlewares;

if (require.main === module){
  var connect = require('connect');
  var app = connect();
  var middlewares = getMiddlewares(connect, [serverConfig.distStatic], serverConfig.dist);

  underscore.each(middlewares, function (middleware) {
    app.use(middleware);
  });

  app.listen(3000);
}<commit_msg>Added port configuration through env variable<commit_after>'use strict';

//var connect = require('connect');
var underscore = require('underscore');
var path = require('path');
var redirectAugumentMiddleware = require('./server/redirectAugmentMiddleware').redirectAugmentMiddleware;
var loginRedirectMiddleware = require('./server/loginRedirectMiddleware').loginRedirectMiddleware;
var loginApplicationMiddleware = require('./server/loginApplicationMiddleware').loginApplicationMiddleware;
var loggedApplicationMiddleware = require('./server/loggedApplicationMiddleware').loggedApplicationMiddleware;
var passport = require('passport');
var serverConfig = {
  app: require('./bower.json').appPath || 'app',
  dist: 'dist',
  server: 'server',
  serverTest: 'server_test'
};
serverConfig.appStatic = serverConfig.app + path.sep + 'static';
serverConfig.distStatic = serverConfig.dist + path.sep + 'static';


var mountFolder = function (connect, dir) {
  return connect.static(path.resolve(dir));
};

function createCommonMiddlewares(connect) {
  return [
    connect.logger(),
    connect.bodyParser(),
    connect.cookieParser(),
    connect.query(),
    connect.session({secret: 'secret'}),
    passport.initialize(),
    passport.session(),
    redirectAugumentMiddleware
  ];
}

function getMiddlewares (connect, staticFolders, applicationDirectory){
  var result = createCommonMiddlewares(connect);

  underscore.each(staticFolders, function (staticFolder) {
    result.push(mountFolder(connect, staticFolder));
  });

  result = result.concat([
    loginRedirectMiddleware,
    loginApplicationMiddleware(applicationDirectory),
    loggedApplicationMiddleware(applicationDirectory)
  ]);

  return result;
}


exports.serverConfig = serverConfig;

exports.getMiddlewares = getMiddlewares;

if (require.main === module){
  var port = process.env.PORT || 5000;
  var connect = require('connect');
  var app = connect();
  var middlewares = getMiddlewares(connect, [serverConfig.distStatic], serverConfig.dist);

  underscore.each(middlewares, function (middleware) {
    app.use(middleware);
  });

  app.listen(port, function(){
    console.log('Server listening on port ' + port);
  });
}
{'fraction_non_alphanumeric': 0.128500823723229, 'fraction_numerical': 0.0018827959519887032, 'mean_word_length': 5.767515923566879, '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': '6553662', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1154, 'n_words': 229}