<commit_before>'use strict';

const logger = require('./lib/logger');
const migrator = require('./migrator');
const { createStores } = require('./lib/db');

const DEFAULT_OPTIONS = {
    databaseUri: process.env.DATABASE_URL || 'postgres://unleash_user:passord@localhost:5432/unleash',
    port: process.env.HTTP_PORT || process.env.PORT || 4242,
    baseUriPath: process.env.BASE_URI_PATH || '',
};

function createApp (options) {
    // Database dependecies (statefull)
    const stores = createStores(options);

    const config = {
        baseUriPath: options.baseUriPath,
        port: options.port,
        publicFolder: options.publicFolder,
        stores,
    };

    const app = require('./app')(config);
    const server = app.listen(app.get('port'), () => {
        logger.info(`Unleash started on ${app.get('port')}`);
    });
    return { app, server };
}

function start (opts) {
    const options = Object.assign({}, DEFAULT_OPTIONS, opts);

    if (!options.databaseUri) {
        throw new Error('You must either pass databaseUri option or set environemnt variable DATABASE_URL');
    }

    return migrator(options.databaseUri)
        .then(() => createApp(options))
        .catch(err => logger.error('failed to migrate db', err));<commit_msg>run require up top<commit_after>'use strict';

const logger = require('./lib/logger');
const migrator = require('./migrator');
const { createStores } = require('./lib/db');
const getApp = require('./app');

const DEFAULT_OPTIONS = {
    databaseUri: process.env.DATABASE_URL || 'postgres://unleash_user:passord@localhost:5432/unleash',
    port: process.env.HTTP_PORT || process.env.PORT || 4242,
    baseUriPath: process.env.BASE_URI_PATH || '',
};

function createApp (options) {
    // Database dependecies (statefull)
    const stores = createStores(options);

    const config = {
        baseUriPath: options.baseUriPath,
        port: options.port,
        publicFolder: options.publicFolder,
        stores,
    };

    const app = getApp(config);
    const server = app.listen(app.get('port'), () => {
        logger.info(`Unleash started on ${app.get('port')}`);
    });
    return { app, server };
}

function start (opts) {
    const options = Object.assign({}, DEFAULT_OPTIONS, opts);

    if (!options.databaseUri) {
        throw new Error('You must either pass databaseUri option or set environemnt variable DATABASE_URL');
    }

    return migrator(options.databaseUri)
        .then(() => createApp(options))
        .catch(err => logger.error('failed to migrate db', err));
{'fraction_non_alphanumeric': 0.1485535574667709, 'fraction_numerical': 0.006254886630179828, 'mean_word_length': 3.3969072164948453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1249821', 'n_tokens_mistral': 781, 'n_tokens_neox': 762, 'n_words': 177}