<commit_before>/**
 * This module is started with bin/run.sh. It sets up a Express HTTP and a Socket.IO Server.
 * Static file Requests are answered directly from this module, Socket.IO messages are passed
 * to MessageHandler and minfied requests are passed to minified.
 */


// Include necessary libraries
var log4js = require('log4js');
var os = require('os');
var socketio = require('socket.io');
var fs = require('fs');
var settings = require('./utils/Settings');
var db = require('./db/DB');
var async = require('async');
var express = require('express');
var path = require('path');
var minify = require('./utils/Minify');
var formidable = require('formidable');


// Includes to be performed asynchronously
var apiHandler;
var exportHandler;
var importHandler;
var exportHTML;
var readOnlyManager;
var padManager;
var securityManager;
var socketIORouter;


// EduWrite routes
var facadeRoutes;
var pageRoutes;
var lectureRoutes;
var courseRoutes;


// Parse application port from parameter
var userPort = null;
if (process.argv[2] != null) {
  userPort = process.argv[2];
}


// Try to get the git version
var version = '';
try {
  var rootPath = path.normalize(__dirname + '/../');
  var ref = fs.readFileSync(rootPath + '.git/HEAD', 'utf-8');
  var refPath = rootPath + '.git/' + ref.substring(5, ref.indexOf('\n'));
  version = fs.readFileSync(refPath, 'utf-8');
  version = version.substring(0, 7);
} catch (error) {
  console.warn("Can't get git version for server header\n" + error.message);
}


// Cache 6 hours
exports.maxAge = 1000 * 60 * 60 * 6;


// Set loglevel
log4js.setGlobalLogLevel(settings.loglevel);


// Asynchronously initialize the database & HTTP server in sequence
async.waterfall([
  initializeDatabase,
  asyncImport,
  initializeHTTPServer
]);


/**
 * Initialize the database
 * @param callback  The callback function to perform on completion (for async waterfall)
 */
function initializeDatabase(callback) {
  db.init(callback);
}


/**
 * Perform all asynchronous imports
 * @param callback  The callback function to perform on completion (for async waterfall)
 */
function asyncImport(callback) {

  // Load etherpad-lite modules that needs a initalized DB
  readOnlyManager = require('./db/ReadOnlyManager');
  exportHTML = require('./utils/ExportHtml');
  exportHandler = require('./handler/ExportHandler');
  importHandler = require('./handler/ImportHandler');
  apiHandler = require('./handler/APIHandler');
  padManager = require('./db/PadManager');
  securityManager = require('./db/SecurityManager');
  socketIORouter = require('./handler/SocketIORouter');

  // Load EduWrite writes, which requires an initialize DB
  //
  facadeRoutes = require('./routes/FacadeRoutes.js');
  pageRoutes = require('./routes/PageRoutes.js');
  lectureRoutes = require('./routes/LectureRoutes.js');
  CourseRoutes = require('./routes/CourseRoutes.js');

  callback(null);
}


/**
 * Initialize the HTTP server
 *  @param callback  The callback function to perform on completion (for async waterfall)
 */
function initializeHTTPServer(callback) {

  // Create server
  var app = express.createServer();

  // Name the server
  app.use(function (req, res, next) {
    var serverName = 'Etherpad-Lite ' + version + ' (http://j.mp/ep-lite)';
    res.header('Server', serverName);
    next();
  });

  //install logging
  var httpLogger = log4js.getLogger('http');
<commit_msg>fixed camelcase<commit_after>/**
 * This module is started with bin/run.sh. It sets up a Express HTTP and a Socket.IO Server.
 * Static file Requests are answered directly from this module, Socket.IO messages are passed
 * to MessageHandler and minfied requests are passed to minified.
 */


// Include necessary libraries
var log4js = require('log4js');
var os = require('os');
var socketio = require('socket.io');
var fs = require('fs');
var settings = require('./utils/Settings');
var db = require('./db/DB');
var async = require('async');
var express = require('express');
var path = require('path');
var minify = require('./utils/Minify');
var formidable = require('formidable');


// Includes to be performed asynchronously
var apiHandler;
var exportHandler;
var importHandler;
var exportHTML;
var readOnlyManager;
var padManager;
var securityManager;
var socketIORouter;


// EduWrite routes
var facadeRoutes;
var pageRoutes;
var lectureRoutes;
var courseRoutes;


// Parse application port from parameter
var userPort = null;
if (process.argv[2] != null) {
  userPort = process.argv[2];
}


// Try to get the git version
var version = '';
try {
  var rootPath = path.normalize(__dirname + '/../');
  var ref = fs.readFileSync(rootPath + '.git/HEAD', 'utf-8');
  var refPath = rootPath + '.git/' + ref.substring(5, ref.indexOf('\n'));
  version = fs.readFileSync(refPath, 'utf-8');
  version = version.substring(0, 7);
} catch (error) {
  console.warn("Can't get git version for server header\n" + error.message);
}


// Cache 6 hours
exports.maxAge = 1000 * 60 * 60 * 6;


// Set loglevel
log4js.setGlobalLogLevel(settings.loglevel);


// Asynchronously initialize the database & HTTP server in sequence
async.waterfall([
  initializeDatabase,
  asyncImport,
  initializeHTTPServer
]);


/**
 * Initialize the database
 * @param callback  The callback function to perform on completion (for async waterfall)
 */
function initializeDatabase(callback) {
  db.init(callback);
}


/**
 * Perform all asynchronous imports
 * @param callback  The callback function to perform on completion (for async waterfall)
 */
function asyncImport(callback) {

  // Load etherpad-lite modules that needs a initalized DB
  readOnlyManager = require('./db/ReadOnlyManager');
  exportHTML = require('./utils/ExportHtml');
  exportHandler = require('./handler/ExportHandler');
  importHandler = require('./handler/ImportHandler');
  apiHandler = require('./handler/APIHandler');
  padManager = require('./db/PadManager');
  securityManager = require('./db/SecurityManager');
  socketIORouter = require('./handler/SocketIORouter');

  // Load EduWrite writes, which requires an initialize DB
  //
  facadeRoutes = require('./routes/FacadeRoutes.js');
  pageRoutes = require('./routes/PageRoutes.js');
  lectureRoutes = require('./routes/LectureRoutes.js');
  courseRoutes = require('./routes/CourseRoutes.js');

  callback(null);
}


/**
 * Initialize the HTTP server
 *  @param callback  The callback function to perform on completion (for async waterfall)
 */
function initializeHTTPServer(callback) {

  // Create server
  var app = express.createServer();

  // Name the server
  app.use(function (req, res, next) {
    var serverName = 'Etherpad-Lite ' + version + ' (http://j.mp/ep-lite)';
    res.header('Server', serverName);
    next();
  });

  //install logging
  var httpLogger = log4js.getLogger('http');

{'fraction_non_alphanumeric': 0.13546870408463121, 'fraction_numerical': 0.006171025565677344, 'mean_word_length': 4.220092024539877, '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': '2431446', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1954, 'n_words': 603}