<commit_before>
import fs = require('fs');
import path = require('path');

import bodyparser = require('body-parser');
import express = require('express');
import favicon = require('serve-favicon');
import morgan = require('morgan');
import session = require('express-session');

import monitor_routes = require('./routes/monitor');

// error interface
interface StatusError extends Error {
  status?: number;
}

// application configuration
interface IAppCfg {
  port?: string;
  addr?: string;
  session_life?: number;
  session_secret?: string;
};

// application singleton
let app: express.Application;

// application logging
let log = console.log;
let warn = console.warn;
let error = console.error;

// read configuration file in JSON format
async function readConfigFile(name: string): Promise<object> {
  return new Promise(function (resolve, reject) {
    fs.readFile(path.resolve(path.resolve(__dirname, '../config', name)), 'utf8', function (err, data) {
      if (err) {
        reject(err);
        return;
      }
      resolve(JSON.parse(data));
    });
  });
};

// Asynchronously start the application
async function start(): Promise<express.Application> {
  if (app) {
    return app;
  }

  log('Application starting');

  app = express();
  let env = app.get('env');

  let cfg: IAppCfg = await readConfigFile('app.json');

  app.set('port', cfg.port || '3000');
  app.set('addr', cfg.addr || 'localhost');

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

  // favicon configuration
  app.use(favicon(path.resolve(__dirname, '../public', 'favicon.ico')));

  // morgan configuration
  morgan.token('remote-user', function (req) {
    if (req.session && req.session.userid) {
      return req.session.userid;
    } else {
      return 'unknown';
    }
  });

  if (env === 'production') {
    app.use(morgan('short'));
  } else {
    app.use(morgan('dev'));
  }

  // body-parser configuration
  app.use(bodyparser.json());
  app.use(bodyparser.urlencoded({
    extended: false,
  }));

  // session configuration
  app.use(session({
    store: new session.MemoryStore(),
    resave: false,
    saveUninitialized: false,
    secret: cfg.session_secret || 'secret',
    cookie: {
      maxAge: cfg.session_life || 28800000,
    },
    logErrors: function(err) {
      // log.error(err);
    },<commit_msg>Rename IAppCfg interface to simply AppCfg<commit_after>
import fs = require('fs');
import path = require('path');

import bodyparser = require('body-parser');
import express = require('express');
import favicon = require('serve-favicon');
import morgan = require('morgan');
import session = require('express-session');

import monitor_routes = require('./routes/monitor');

// error interface
interface StatusError extends Error {
  status?: number;
}

// application configuration
interface AppCfg {
  port?: string;
  addr?: string;
  session_life?: number;
  session_secret?: string;
};

// application singleton
let app: express.Application;

// application logging
let log = console.log;
let warn = console.warn;
let error = console.error;

// read configuration file in JSON format
async function readConfigFile(name: string): Promise<object> {
  return new Promise(function (resolve, reject) {
    fs.readFile(path.resolve(path.resolve(__dirname, '../config', name)), 'utf8', function (err, data) {
      if (err) {
        reject(err);
        return;
      }
      resolve(JSON.parse(data));
    });
  });
};

// Asynchronously start the application
async function start(): Promise<express.Application> {
  if (app) {
    return app;
  }

  log('Application starting');

  app = express();
  let env = app.get('env');

  let appCfg: AppCfg = await readConfigFile('app.json');

  app.set('port', appCfg.port || '3000');
  app.set('addr', appCfg.addr || 'localhost');

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

  // favicon configuration
  app.use(favicon(path.resolve(__dirname, '../public', 'favicon.ico')));

  // morgan configuration
  morgan.token('remote-user', function (req) {
    if (req.session && req.session.userid) {
      return req.session.userid;
    } else {
      return 'unknown';
    }
  });

  if (env === 'production') {
    app.use(morgan('short'));
  } else {
    app.use(morgan('dev'));
  }

  // body-parser configuration
  app.use(bodyparser.json());
  app.use(bodyparser.urlencoded({
    extended: false,
  }));

  // session configuration
  app.use(session({
    store: new session.MemoryStore(),
    resave: false,
    saveUninitialized: false,
    secret: appCfg.session_secret || 'secret',
    cookie: {
      maxAge: appCfg.session_life || 28800000,
    },
    logErrors: function(err) {
      // log.error(err);
    },
{'fraction_non_alphanumeric': 0.16043001860657433, 'fraction_numerical': 0.0053752325821790365, 'mean_word_length': 3.5727788279773156, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1407939', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1450, 'n_words': 361}