<commit_before>'use strict';

/**
 * Rhizome - The API that feeds grassroots movements
 *
 * @file app.js
 * @description
 * @module System
 * @author <NAME>
 *
 */

const express = require('express');
const app = module.exports = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);

const methodOverride = require('method-override');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const mongoose = require('mongoose');
const Bootstrap = require('./bootstrap');
const Config = require('./config');
const Logging = require('./logging');

/**
 * Configuration
 */
const configureDevelopment = () => {
  Config.env = 'dev';
  app.set('db-uri', `mongodb://${Config.RHIZOME_MONGO_URL_DEV}/${Config.app.code}-dev`);
  app.use(morgan('short'));
  app.set('port', Config.listenPort);
};

const configureProduction = () => {
  Config.env = 'prod';
  app.set('db-uri', `mongodb://${Config.RHIZOME_MONGO_URL_PROD}/${Config.app.code}-prod`);
  app.use(morgan('short'));
  app.set('port', Config.listenPort);
};

const configureTest = () => {
  Config.env = 'test';
  app.set('db-uri', `mongodb://${Config.RHIZOME_MONGO_URL_TEST}/${Config.app.code}-test`);
  app.use(morgan('short'));
  app.set('port', Config.listenPort);
};

const configureApp = env => {
  app.enable('trust proxy', 1);
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(methodOverride());

  app.use(express.static(`${Config.appDataPath}/public`));

  switch (env) {
    default:
    case 'development':
      configureDevelopment();
      break;
    case 'production':
      configureProduction();
      break;
    case 'test':
      configureTest();
      break;
  }
};

configureApp(app.get('env'));

/**
 *
 */
app.db = mongoose.connect(app.get('db-uri'));
app.db.connection.on('connected', () => {
  Bootstrap
    .app(app, io)
    .then(() => {
      Logging.log(`${Config.app.title} v${Config.app.version} listening on port ` +
        `${app.get('port')} in ${app.settings.env} mode.`, Logging.Constants.LogLevel.INFO);
      app.server = server.listen(app.set('port'));
    })
    .catch(Logging.Promise.logError());
});
<commit_msg>- REMOVED: Socket IO initialisation. This is now the REST App. - ENHANCED: Using the new config to simplify the mongoDb Url.<commit_after>'use strict';

/**
 * Rhizome - The API that feeds grassroots movements
 *
 * @file app.js
 * @description
 * @module System
 * @author <NAME>
 *
 */

const express = require('express');
const app = module.exports = express();
const server = require('http').createServer(app);

const methodOverride = require('method-override');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const mongoose = require('mongoose');
const Bootstrap = require('./bootstrap');
const Config = require('./config');
const Logging = require('./logging');

/**
 * Configuration
 */
const configureDevelopment = () => {
  Config.env = 'dev';
  app.set('db-uri', `mongodb://${Config.mongoDb.url}/${Config.app.code}-dev`);
  app.use(morgan('short'));
  app.set('port', Config.listenPort);
};

const configureProduction = () => {
  Config.env = 'prod';
  app.set('db-uri', `mongodb://${Config.mongoDb.url}/${Config.app.code}-prod`);
  app.use(morgan('short'));
  app.set('port', Config.listenPort);
};

const configureTest = () => {
  Config.env = 'test';
  app.set('db-uri', `mongodb://${Config.mongoDb.url}/${Config.app.code}-test`);
  app.use(morgan('short'));
  app.set('port', Config.listenPort);
};

const configureApp = env => {
  app.enable('trust proxy', 1);
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(methodOverride());

  app.use(express.static(`${Config.appDataPath}/public`));

  switch (env) {
    default:
    case 'development':
      configureDevelopment();
      break;
    case 'production':
      configureProduction();
      break;
    case 'test':
      configureTest();
      break;
  }
};

configureApp(app.get('env'));

/**
 *
 */
app.db = mongoose.connect(app.get('db-uri'));
app.db.connection.on('connected', () => {
  Bootstrap
    .rest(app)
    .then(() => {
      Logging.log(`${Config.app.title} REST Server v${Config.app.version} listening on port ` +
        `${app.get('port')} in ${app.settings.env} mode.`, Logging.Constants.LogLevel.INFO);
      app.server = server.listen(app.set('port'));
    })
    .catch(Logging.Promise.logError());
});

{'fraction_non_alphanumeric': 0.20369957655449075, 'fraction_numerical': 0.0004457321149988857, 'mean_word_length': 4.008928571428571, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2081471', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1462, 'n_words': 268}