<commit_before>import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import readline from 'readline';
import express from 'express';
import redis from 'redis';
import debug from 'debug';

// APIs
import v1 from './routes/v1/api.js';

// config
import serverConfig from './config/server.json';
import apiConfig from './config/api.json';

const mongoOptions = {
  'db': { 'native_parser': true },
  'server': { 'poolSize': 5 },
  'user': serverConfig.db.mongo.user,
  'pass': serverConfig.db.mongo.pass
};

const app = express();
const mongo = mongoose.connection;

const serverLog = debug("uwave:server");
const mongoLog = debug("uwave:database:mongo");

mongo.on('error', e => mongoLog(e));
mongo.on('reconnected', () => mongoLog("reconnected"));
mongo.on('disconnected', () => mongoLog("disconnected"))

mongo.once('open', () => {
  // Initialize app now that we have a connection to the database
  mongoLog('connection successfull');
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));

  // here you can invoke further API versions
  v1(app, apiConfig.v1);
});


// workaround to properly close all connections on termination.
if(process.platform === "win32") {
  readline.createInterface({
    'input': process.stdin,
    'output': process.stdout
  }).on('SIGINT', () => process.emit('SIGINT'));
}

process.on('SIGINT', () => {
  mongoose.connection.close(() => {
    mongoLog('closing connection to mongo');
    process.exit(0);
  });
});

mongoLog(`connecting to database '${serverConfig.db.mongo.host}/uwave'...`);
mongoose.connect(`mongodb://${serverConfig.db.mongo.host}/uwave:${serverConfig.db.mongo.port}`, mongoOptions);<commit_msg>move mongo config to config/mongo.json<commit_after>import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import readline from 'readline';
import express from 'express';
import redis from 'redis';
import debug from 'debug';

// APIs
import v1 from './routes/v1/api.js';

// config
import serverConfig from './config/server.json';
import mongoConfig from './config/mongo.json';
import apiConfig from './config/api.json';

const app = express();
const mongo = mongoose.connection;

const serverLog = debug("uwave:server");
const mongoLog = debug("uwave:database:mongo");

mongo.on('error', e => mongoLog(e));
mongo.on('reconnected', () => mongoLog("reconnected"));
mongo.on('disconnected', () => mongoLog("disconnected"))

mongo.once('open', () => {
  // Initialize app now that we have a connection to the database
  mongoLog('connection successfull');
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));

  // here you can invoke further API versions
  v1(app, apiConfig.v1);
});


// workaround to properly close all connections on termination.
if(process.platform === "win32") {
  readline.createInterface({
    'input': process.stdin,
    'output': process.stdout
  }).on('SIGINT', () => process.emit('SIGINT'));
}

process.on('SIGINT', () => {
  mongoose.connection.close(() => {
    mongoLog('closing connection to mongo');
    process.exit(0);
  });
});

mongoLog(`connecting to database '${mongoConfig.host}/uwave'...`);
mongoose.connect(`mongodb://${mongoConfig.host}/uwave:${mongoConfig.port}`, mongoConfig.options);
{'fraction_non_alphanumeric': 0.1778389960208142, 'fraction_numerical': 0.004591368227731864, 'mean_word_length': 4.941818181818181, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2702675', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1044, 'n_words': 247}