<commit_before>var nodemailer = require('nodemailer'),
    express    = require('express'),
    flatten    = require('flatten').flatten,
    hogan      = require('hogan.js'),
    gobo       = require('gobo'),
    path       = require('path'),
    fs         = require('fs'),
    app        = express.createServer(),
    errors     = require('./errors'),
    options    = require('./config'),
    spike      = require('./spike'),
    store      = require('./store')(options.store),
    models     = require('./models'),
    handlers   = require('./handlers'),
    middleware = require('./middleware'),
    mailTransport = nodemailer.createTransport('smtp', options.smtp),
    mailHandler = new handlers.MailHandler(mailTransport, app.render.bind(app)),
    sessionHandler = new handlers.SessionHandler(),
    binHandler = new handlers.BinHandler(),
    flattened;

app.store  = store;
app.spike  = spike;
app.models = models.createModels(store);
app.templates = {};
app.mailer = mailHandler;

app.PRODUCTION  = 'production';
app.DEVELOPMENT = 'development';

// Apply the keys from the config file. All nested properties are
// space delimited to match the express style.
//
// For example, app.set('url prefix'); //=> '/'
flattened = flatten(options, ' ');
Object.getOwnPropertyNames(flattened).forEach(function (key) {
  app.set(key, flattened[key]);
});

app.set('root', path.resolve(path.join(__dirname, '..')));
app.set('version', require('../package').version);
app.set('url prefix', options.url.prefix.replace(/\/$/, ''));
app.set('url full', (app.set('url ssl') ? 'https://' : 'http://') + app.set('url host') + app.set('url prefix'));

// Register all the middleware.
app.use(express.logger('tiny'));
app.use(express.static(path.join(app.set('root'), 'public')));
app.use(express.cookieParser(app.set('session secret')));
app.use(express.cookieSession({key: 'jsbin'}));
app.use(express.bodyParser());
app.use(express.csrf());
app.use(middleware.subdomain(app));
app.use(middleware.noslashes());
app.use(middleware.ajax());
app.use(middleware.cors());
app.use(middleware.jsonp());
app.use(middleware.helpers(app));
<commit_msg>Create a sandbox object and pass it into the handlers<commit_after>var nodemailer = require('nodemailer'),
    express    = require('express'),
    flatten    = require('flatten').flatten,
    hogan      = require('hogan.js'),
    gobo       = require('gobo'),
    path       = require('path'),
    fs         = require('fs'),
    app        = express.createServer(),
    errors     = require('./errors'),
    options    = require('./config'),
    spike      = require('./spike'),
    store      = require('./store')(options.store),
    models     = require('./models'),
    helpers    = require('./helpers'),
    handlers   = require('./handlers'),
    middleware = require('./middleware'),
    mailTransport = nodemailer.createTransport('smtp', options.smtp),
    mailHandler = new handlers.MailHandler(mailTransport, app.render.bind(app)),
    sandbox, sessionHandler, binHandler, flattened;

app.store  = store;
app.spike  = spike;
app.models = models.createModels(store);
app.templates = {};
app.mailer = mailHandler;

app.PRODUCTION  = 'production';
app.DEVELOPMENT = 'development';

// A sandbox object to contain some specific objects that are commonly used by
// handlers. In future it would be ideal that each handler only receives the
// objects that it requires.
sandbox = {
  store: app.store,
  models: app.models,
  mailer: app.mailer,
  helpers: helpers.createHelpers(app)
};

// Create handlers for accepting incoming requests.
binHandler = new handlers.BinHandler(sandbox);
sessionHandler = new handlers.SessionHandler(sandbox);

// Apply the keys from the config file. All nested properties are
// space delimited to match the express style.
//
// For example, app.set('url prefix'); //=> '/'
flattened = flatten(options, ' ');
Object.getOwnPropertyNames(flattened).forEach(function (key) {
  app.set(key, flattened[key]);
});

app.set('root', path.resolve(path.join(__dirname, '..')));
app.set('version', require('../package').version);
app.set('url prefix', options.url.prefix.replace(/\/$/, ''));
app.set('url full', (app.set('url ssl') ? 'https://' : 'http://') + app.set('url host') + app.set('url prefix'));

// Register all the middleware.
app.use(express.logger('tiny'));
app.use(express.static(path.join(app.set('root'), 'public')));
app.use(express.cookieParser(app.set('session secret')));
app.use(express.cookieSession({key: 'jsbin'}));
app.use(express.bodyParser());
app.use(express.csrf());
app.use(middleware.subdomain(app));
app.use(middleware.noslashes());
app.use(middleware.ajax());
app.use(middleware.cors());
app.use(middleware.jsonp());
app.use(middleware.helpers(app));

{'fraction_non_alphanumeric': 0.18563000421407502, 'fraction_numerical': 0.0, 'mean_word_length': 4.082441113490364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '41787', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1457, 'n_words': 303}