<commit_before>require('./exitHandler')();

module.exports = function (callback) {
    var hooks,
        fs = require('fs'),
        config = require(process.cwd() +'/config');

    // Prevent Version Issue
    if (fs.existsSync(process.cwd() +'/hooks.js')) {
        hooks = require(process.cwd() +'/hooks');
    } else {
        console.log("Glad supports a hooks file. Grab one from our github at http://raw.githubusercontent.com/charliemitchell/nimble/master/blueprint/hooks.js");
        hooks = {};
    }
        
    // Support Hiding the logo
    if (config.hideLogo !== true) {
        require('./logo')();
    } else {
        console.log("  > Service Starting...".green)
    }

    var application_root = __dirname,
        globalReport = require('./globalReport'),
        express = require("express"),
        path = require("path"),
        mongoose = require('mongoose'),
        app = express(),
        server = require('http').Server(app),
        middleware = require(process.cwd() +'/middleware'),
        colors = require('colors'),
        cookieParser = require('cookie-parser'),
        policies = require(process.cwd() +'/policies'),
        verbose = require('./logger').onVerbose,
        fs = require('fs'),
        applyPolicy = function (policy, method) {
            return function (req, res) {

                var accept = function () {
                        method(req, res);
                    },
                    reject = function (custom) {
                        policies.onFailure(req, res, custom);
                    };

                if (policy) {
                    if (policies[policy]) {
                        policies[policy](req, res, accept, reject);
                    } else {
                        console.log(("Glad: The Policy '" + policy + "' Does Not exist, therefore the request was denied").red);
                        reject();
                    }
                } else { // No Policy, Allow it
                    method(req, res);
                }
            }
        },
        routes_path = path.join(process.cwd(),  'routes'),
        controllers_path = path.join(process.cwd(), 'controllers'),
        routes = {}, controllers={};


    (function () {
        var files = fs.readdirSync(routes_path);
        files.forEach(function(file) {
            var route = path.join(routes_path, file);
            routes[file.replace('.js', '')] = require(route);
        });
    }());

    (function () {
        var files = fs.readdirSync(controllers_path);
        files.forEach(function(file) {
            var controller = path.join(controllers_path, file);
            controllers[file.replace('.js', '')] = require(controller);
        });
    }());


    if (hooks.app) {
        verbose("Glad: Configuring App");
        hooks.app(server, app, express);
    }

    verbose("Glad: Exposing Global Objects".yellow);

    // Expose any Globals
    require(process.cwd() +'/globals')(global, function () {
        
        verbose('Glad: Globals Registered ::'.magenta, (globalReport()).magenta);
        
        if (hooks.onBeforeMongoose) {
            verbose("Glad: Configuring Mongoose");
            hooks.onBeforeMongoose(mongoose, server, app, express);
        }

        if (config.mongodb) {
            // Connect To MongoDB using our ORM
            mongoose.connect('mongodb://'+config.mongodb.host+':'+config.mongodb.port + '/' + config.mongodb.database);<commit_msg>Fixing an issue with OSX where the .DS_Store file would cause the service file to crash.<commit_after>require('./exitHandler')();

module.exports = function (callback) {
    var hooks,
        fs = require('fs'),
        config = require(process.cwd() +'/config');

    // Prevent Version Issue
    if (fs.existsSync(process.cwd() +'/hooks.js')) {
        hooks = require(process.cwd() +'/hooks');
    } else {
        console.log("Glad supports a hooks file. Grab one from our github at http://raw.githubusercontent.com/charliemitchell/nimble/master/blueprint/hooks.js");
        hooks = {};
    }
        
    // Support Hiding the logo
    if (config.hideLogo !== true) {
        require('./logo')();
    } else {
        console.log("  > Service Starting...".green)
    }

    var application_root = __dirname,
        globalReport = require('./globalReport'),
        express = require("express"),
        path = require("path"),
        mongoose = require('mongoose'),
        app = express(),
        server = require('http').Server(app),
        middleware = require(process.cwd() +'/middleware'),
        colors = require('colors'),
        cookieParser = require('cookie-parser'),
        policies = require(process.cwd() +'/policies'),
        verbose = require('./logger').onVerbose,
        fs = require('fs'),
        applyPolicy = function (policy, method) {
            return function (req, res) {

                var accept = function () {
                        method(req, res);
                    },
                    reject = function (custom) {
                        policies.onFailure(req, res, custom);
                    };

                if (policy) {
                    if (policies[policy]) {
                        policies[policy](req, res, accept, reject);
                    } else {
                        console.log(("Glad: The Policy '" + policy + "' Does Not exist, therefore the request was denied").red);
                        reject();
                    }
                } else { // No Policy, Allow it
                    method(req, res);
                }
            }
        },
        routes_path = path.join(process.cwd(),  'routes'),
        controllers_path = path.join(process.cwd(), 'controllers'),
        routes = {}, controllers={};


    (function () {
        var files = fs.readdirSync(routes_path);
        files.forEach(function(file) {
            if (!file.match(/\.DS_Store/)) {
                var route = path.join (routes_path, file);
                routes[file.replace ('.js', '')] = require (route);
            }
        });
    }());

    (function () {
        var files = fs.readdirSync(controllers_path);
        files.forEach(function(file) {
            if (!file.match(/\.DS_Store/)){
                var controller = path.join(controllers_path, file);
                controllers[file.replace('.js', '')] = require(controller);
            }
        });
    }());


    if (hooks.app) {
        verbose("Glad: Configuring App");
        hooks.app(server, app, express);
    }

    verbose("Glad: Exposing Global Objects".yellow);

    // Expose any Globals
    require(process.cwd() +'/globals')(global, function () {
        
        verbose('Glad: Globals Registered ::'.magenta, (globalReport()).magenta);
        
        if (hooks.onBeforeMongoose) {
            verbose("Glad: Configuring Mongoose");
            hooks.onBeforeMongoose(mongoose, server, app, express);
        }

        if (config.mongodb) {
            // Connect To MongoDB using our ORM
            mongoose.connect('mongodb://'+config.mongodb.host+':'+config.mongodb.port + '/' + config.mongodb.database);
{'fraction_non_alphanumeric': 0.14711229198713466, 'fraction_numerical': 0.0, 'mean_word_length': 1.8047058823529412, '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': '3539664', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1942, 'n_words': 411}