<commit_before>/*!
 * nodeclub - app.js
 */

/**
 * Module dependencies.
 */

var path = require('path');
var express = require('express');
var Recaptcha = require('recaptcha').Recaptcha;
var PUBLIC_KEY  = 'YOUR_PUBLIC_KEY',
        PRIVATE_KEY = 'YOUR_PRIVATE_KEY';

var ndir = require('ndir');
var config = require('./config').config;
// host: http://127.0.0.1
var urlinfo = require('url').parse(config.host);
config.hostname = urlinfo.hostname || config.host;
var routes = require('./routes');

config.upload_dir = config.upload_dir || path.join(__dirname, 'public', 'user_data', 'images');
// ensure upload dir exists
ndir.mkdir(config.upload_dir, function (err) {
  if (err) {
    throw err;
  }
});

var app = express.createServer();

// configuration in all env
app.configure(function () {
  var viewsRoot = path.join(__dirname, 'views');
  app.set('view engine', 'html');
  app.set('views', viewsRoot);
  app.register('.html', require('ejs'));
  app.use(express.bodyParser({
    uploadDir: config.upload_dir
  }));
  app.use(express.cookieParser());
  app.use(express.session({
    secret: config.session_secret
  }));
  // custom middleware
  app.use(require('./controllers/sign').auth_user);
  
  var csrf = express.csrf();
  app.use(function (req, res, next) {
    // ignore upload image
    if (req.body && req.body.user_action === 'upload_image') {
      return next();
    }
    csrf(req, res, next);
  });
});

app.get('/', function(req, res) {
    var recaptcha = new Recaptcha(PUBLIC_KEY, PRIVATE_KEY);

    res.render('form.jade', {
        layout: false,
        locals: {
            recaptcha_form: recaptcha.toHTML()
        }
    });
});

app.post('/', function(req, res) {
    var data = {
        remoteip:  req.connection.remoteAddress,
    challenge: req.body.recaptcha_challenge_field,
    response:  req.body.recaptcha_response_field
    };
    var recaptcha = new Recaptcha(PUBLIC_KEY, PRIVATE_KEY, data);

    recaptcha.verify(function(success, error_code) {
        if (success) {
            res.send('Recaptcha response valid.');
        }
        else {
            // Redisplay the form.
            res.render('form.jade', {
                layout: false,
                locals: {
                    recaptcha_form: recaptcha.toHTML()
                }
            });
        }
    });
});

app.listen(3000);

if (process.env.NODE_ENV !== 'test') {
  // plugins
  var plugins = config.plugins || [];
  for (var i = 0, l = plugins.length; i < l; i++) {
    var p = plugins[i];
    app.use(require('./plugins/' + p.name)(p.options));
  }
}

// set static, dynamic helpers
app.helpers({
  config: config
});
app.dynamicHelpers({
  csrf: function (req, res) {
    return req.session ? req.session._csrf : '';
  }
});

var maxAge = 3600000 * 24 * 30;
app.use('/upload/', express.static(config.upload_dir, { maxAge: maxAge }));
// old image url: http://host/user_data/images/xxxx
app.use('/user_data/', express.static(path.join(__dirname, 'public', 'user_data'), { maxAge: maxAge }));

var staticDir = path.join(__dirname, 'public');
app.configure('development', function () {
  app.use(express.static(staticDir));
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
});
<commit_msg>working again<commit_after>/*!
 * nodeclub - app.js
 */

/**
 * Module dependencies.
 */

var path = require('path');
var express = require('express');
//var Recaptcha = require('recaptcha').Recaptcha;

var ndir = require('ndir');
var config = require('./config').config;
// host: http://127.0.0.1
var urlinfo = require('url').parse(config.host);
config.hostname = urlinfo.hostname || config.host;
var routes = require('./routes');

config.upload_dir = config.upload_dir || path.join(__dirname, 'public', 'user_data', 'images');
// ensure upload dir exists
ndir.mkdir(config.upload_dir, function (err) {
  if (err) {
    throw err;
  }
});

var app = express.createServer();

// configuration in all env
app.configure(function () {
  var viewsRoot = path.join(__dirname, 'views');
  app.set('view engine', 'html');
  app.set('views', viewsRoot);
  app.register('.html', require('ejs'));
  app.use(express.bodyParser({
    uploadDir: config.upload_dir
  }));
  app.use(express.cookieParser());
  app.use(express.session({
    secret: config.session_secret
  }));
  // custom middleware
  app.use(require('./controllers/sign').auth_user);
  
  var csrf = express.csrf();
  app.use(function (req, res, next) {
    // ignore upload image
    if (req.body && req.body.user_action === 'upload_image') {
      return next();
    }
    csrf(req, res, next);
  });
});

if (process.env.NODE_ENV !== 'test') {
  // plugins
  var plugins = config.plugins || [];
  for (var i = 0, l = plugins.length; i < l; i++) {
    var p = plugins[i];
    app.use(require('./plugins/' + p.name)(p.options));
  }
}

// set static, dynamic helpers
app.helpers({
  config: config
});
app.dynamicHelpers({
  csrf: function (req, res) {
    return req.session ? req.session._csrf : '';
  }
});

var maxAge = 3600000 * 24 * 30;
app.use('/upload/', express.static(config.upload_dir, { maxAge: maxAge }));
// old image url: http://host/user_data/images/xxxx
app.use('/user_data/', express.static(path.join(__dirname, 'public', 'user_data'), { maxAge: maxAge }));

var staticDir = path.join(__dirname, 'public');
app.configure('development', function () {
  app.use(express.static(staticDir));
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
});

{'fraction_non_alphanumeric': 0.1803757067298924, 'fraction_numerical': 0.007295276308590188, 'mean_word_length': 3.321513002364066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5761002', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1817, 'n_words': 381}