<commit_before>/*jshint esversion:6, node:true*/
'use strict';

const extend = require('gextend');

var DEFAULTS = {
    middleware: {
        use:   require('./middleware').use,
        order: require('./middleware').order,
    }
};

module.exports.init = function(context, config){

    const express = require('express');
    var app = express();

    /*
     * Enable middleware to use context,
     * i.e. to publish an event system wide.
     * context.emit('web.request.createUser', user);
     */
    config.context = context;

    /*
     * Create a logger for our express app.
     * This can be trickled down to middleware
     * as well.
     */
    config.logger = context.getLogger(config.name);

    /*
     * basedir will be used by middleware to
     * find the `public` directory, `views`,
     * etc...
     */
    config.basedir = __dirname;

    setup(app, config);

    return app;
};

function setup(app, config){

    config = extend({}, DEFAULTS, config);

    var use = config.middleware.use;

    var order = config.middleware.order;

    order.map((middleware)=>{
        use[middleware](app, config);
    });
}<commit_msg>defaultApp: take basedir from config<commit_after>/*jshint esversion:6, node:true*/
'use strict';

const extend = require('gextend');

var DEFAULTS = {
    middleware: {
        use:   require('./middleware').use,
        order: require('./middleware').order,
    }
};

module.exports.init = function(context, config){

    const express = require('express');
    var app = express();

    /*
     * Enable middleware to use context,
     * i.e. to publish an event system wide.
     * context.emit('web.request.createUser', user);
     */
    config.context = context;

    /*
     * Create a logger for our express app.
     * This can be trickled down to middleware
     * as well.
     */
    config.logger = context.getLogger(config.name);

    /*
     * basedir will be used by middleware to
     * find the `public` directory, `views`,
     * etc...
     */
    if(!config.basedir){
        config.basedir = __dirname;
        config.logger.warn('You did not specify a "basedir"?');
        config.logger.warn('We are making a guess: %s', config.basedir);
    } else {
        config.logger.warn('Loading views and assets from: %s', config.basedir);
    }

    setup(app, config);

    return app;
};

function setup(app, config){

    config = extend({}, DEFAULTS, config);

    var use = config.middleware.use;

    var order = config.middleware.order;

    order.map((middleware)=>{
        use[middleware](app, config);
    });
}
{'fraction_non_alphanumeric': 0.14164415283674256, 'fraction_numerical': 0.0007719027402547279, 'mean_word_length': 2.50744248985115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2529841', 'n_tokens_mistral': 797, 'n_tokens_neox': 777, 'n_words': 212}