<commit_before>var express     = require('express'),
    path        = require('path'),
    morgan      = require('morgan'),
    colors      = require('colors'),
    mongoose    = require('mongoose'),
    fs          = require('fs'),
    app         = express(),
    opts        = require('nomnom')
        .usage('Start webserver.\nUsage: $0')
        .option('port', {
            abbr: 'p',
            flag: true,
            default: 8080,
            help: 'Listen port webserver'
        })
        .option('debug', {
            abbr: 'd',
            flag: true,
            default: true,
            help: 'Print debugging info'
        })
        .option('config', {
            abbr: 'c',
            default: 'config.json',
            help: 'JSON file with tests to run'
        })
        .option('dirname', {
            default: __dirname,
            help: 'Root App directory'
        })
        .option('version', {
            flag: true,
            help: 'print version and exit',
            callback: function() {
                return "version 1.2.4";
            }
        })
        .parse()

var cfg     = JSON.parse(fs.readFileSync(opts.config, 'utf8'));

//mongoose.connect('mongodb://localhost:27017/polls');

morgan.format('app', [
        'HTTP/:http-version'.magenta,
        '<--'.green,
        ':status'.yellow,
        '\':method :url\''.green,
        ':res[content-length]'.yellow,
        'bytes',
        ':response-time'.yellow,
        'ms'
    ].join(' '));

morgan.token('bodypased', function(req, res){
    return JSON.stringify(req.body, null, 2);
})

morgan.format('api', [
        '[API]'.blue,
        'HTTP/:http-version'.magenta,
        '<--'.blue,
        ':status'.yellow,
        '\':method :url\''.green,
        ':res[content-length]'.yellow,
        'bytes',
        ':response-time'.yellow,
        'ms',
        ':bodypased'

    ].join(' '));

// Configuración
// app.configure(function() {
//     // Localización de los ficheros estÃ¡ticos
//     app.use(express.static(__dirname + '/public'));
//     // Muestra un log de todos los request en la consola
//     app.use(express.logger('dev'));
//     // Permite cambiar el HTML con el método POST
//     app.use(express.bodyParser());
//     // Simula DELETE y PUT
//     app.use(express.methodOverride());
// });

// configure app to use bodyParser()
// this will let us get the data from a POST

app.orm = require('./orm/orm.js')({
    hostname: 'localhost',
    port: 27017,
    db: 'polls'
});

app.io = require('socket.io')(app.server);

// app.use(require('node-sass').middleware({
//          src: __dirname + '/app/scss', //where the sass files are
//          dest: __dirname + '/public', //where css should go
//          debug: true // obvious
// }));

app
    .use('/api', require('./api/api.js')(app, opts, cfg.api))
    .use('/',    require('./server/server.js')(app, opts, cfg.app))
    .listen(opts.port, function() {
        opts.debug && app.use(morgan('app'));
        console.log('App listening on port ' + opts.port);
    });

app.io.on('connection', function() {
    console.log('Socket.io Connected');
});

//console.log(orm.models.role.read);

//console.log(app.orm.models.user.create.toString());
app.orm.auth('admin', ['admin']);
app.orm.models.user.create({
    _id: (10000000+Math.floor(Math.random()*1000000))+'M',
    name: {
        first: 'jurjut'
    },
    password: <PASSWORD>
}, function(err){
    console.log(err);
}).then(function(){
    console.log('Success', arguments);
}, function(err){
    console.log('Error', err, JSON.stringify(err, null , 4));
});

// app.orm.models.user.findOne({
//     _id: '10477185M'
// }, function(err){
//     console.log(err);
// }).then(function(){
//     console.log('Success', arguments);
// }, function(err){
//     console.log('Error', err, JSON.stringify(err, null , 4));
// });<commit_msg>add: include io server handler<commit_after>var express     = require('express'),
    path        = require('path'),
    morgan      = require('morgan'),
    colors      = require('colors'),
    mongoose    = require('mongoose'),
    fs          = require('fs'),
    app         = express(),
    http        = require( 'http' ).createServer( app ),
    opts        = require('nomnom')
        .usage('Start webserver.\nUsage: $0')
        .option('port', {
            abbr: 'p',
            flag: true,
            default: 8080,
            help: 'Listen port webserver'
        })
        .option('debug', {
            abbr: 'd',
            flag: true,
            default: true,
            help: 'Print debugging info'
        })
        .option('config', {
            abbr: 'c',
            default: 'config.json',
            help: 'JSON file with tests to run'
        })
        .option('dirname', {
            default: __dirname,
            help: 'Root App directory'
        })
        .option('version', {
            flag: true,
            help: 'print version and exit',
            callback: function() {
                return "version 1.2.4";
            }
        })
        .parse()

var cfg     = JSON.parse(fs.readFileSync(opts.config, 'utf8'));

//mongoose.connect('mongodb://localhost:27017/polls');

morgan.format('app', [
        'HTTP/:http-version'.magenta,
        '<--'.green,
        ':status'.yellow,
        '\':method :url\''.green,
        ':res[content-length]'.yellow,
        'bytes',
        ':response-time'.yellow,
        'ms'
    ].join(' '));

morgan.token('<PASSWORD>', function(req, res){
    return JSON.stringify(req.body, null, 2);
})

morgan.format('api', [
        '[API]'.blue,
        'HTTP/:http-version'.magenta,
        '<--'.blue,
        ':status'.yellow,
        '\':method :url\''.green,
        ':res[content-length]'.yellow,
        'bytes',
        ':response-time'.yellow,
        'ms',
        ':bodypased'

    ].join(' '));

// Configuración
// app.configure(function() {
//     // Localización de los ficheros estÃ¡ticos
//     app.use(express.static(__dirname + '/public'));
//     // Muestra un log de todos los request en la consola
//     app.use(express.logger('dev'));
//     // Permite cambiar el HTML con el método POST
//     app.use(express.bodyParser());
//     // Simula DELETE y PUT
//     app.use(express.methodOverride());
// });

// configure app to use bodyParser()
// this will let us get the data from a POST

app.orm = require('./orm/orm.js')({
    hostname: 'localhost',
    port: 27017,
    db: 'polls'
});

// app.use(require('node-sass').middleware({
//          src: __dirname + '/app/scss', //where the sass files are
//          dest: __dirname + '/public', //where css should go
//          debug: true // obvious
// }));

app
    .use('/api', require('./api/api.js')(app, opts, cfg.api))
    .use('/',    require('./server/server.js')(app, opts, cfg.app));


app.io = require('./io/io.js')(http);

//console.log(orm.models.role.read);

//console.log(app.orm.models.user.create.toString());
app.orm.auth('admin', ['admin']);
app.orm.models.user.create({
    _id: (10000000+Math.floor(Math.random()*1000000))+'M',
    name: {
        first: 'jurjut'
    },
    password: <PASSWORD>
}, function(err){
    console.log(err);
}).then(function(){
    console.log('Success', arguments);
}, function(err){
    console.log('Error', err, JSON.stringify(err, null , 4));
});

// app.orm.models.user.findOne({
//     _id: '10477185M'
// }, function(err){
//     console.log(err);
// }).then(function(){
//     console.log('Success', arguments);
// }, function(err){
//     console.log('Error', err, JSON.stringify(err, null , 4));
// });

http.listen(opts.port, function() {
        opts.debug && app.use(morgan('app'));
        console.log('App listening on port ' + opts.port);
    });
{'fraction_non_alphanumeric': 0.19482025512176265, 'fraction_numerical': 0.011596443757247778, 'mean_word_length': 2.0451157316594744, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1925928', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2451, 'n_words': 501}