<commit_before>"use strict";

var logger = require('nlogger').logger(module);
var express = require('express');
var _ = require('underscore');
var config = require('./config');
var poller = require('./poller');

var app = module.exports = express.createServer();
var reports = {};


function reapOldReports() {
  logger.info('starting reap cycle on {} reports', _.keys(reports).length);
  _.each(_.keys(reports), function(key) {
    var report = reports[key];
    var age = Math.round(((new Date()).getTime() - report.reported)/1000);
    if (age >= config.reapAge) {
      logger.info('reaping stale report for: {}:{}', report.host, report.port);
      delete reports[key];
    }
  });
}

poller.emitter.on('report', function(report) {
  var key = report.host + ':' + report.port;
  reports[key] = report;
});

app.configure(function() {
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express.static(__dirname + '/pages', { maxAge: 60*60 }));
    app.use(express.static(__dirname + '/static', { maxAge: 3*24*60*60 }));
});

app.get('/reports', function(req, res) {
  res.setHeader('Content-Type', 'application/json');
  res.setHeader('Cache-Control', 'public, max-age=' + 10);
  res.send(JSON.stringify(reports));
  res.end();
});

logger.info('starting web UI on port: {}', config.httpPort)
app.listen(config.httpPort);
poller.startPollingMasterServer();
setInterval(reapOldReports, config.reapInterval*1000);<commit_msg>add error handler for express<commit_after>"use strict";

var logger = require('nlogger').logger(module);
var express = require('express');
var _ = require('underscore');
var config = require('./config');
var poller = require('./poller');

var app = module.exports = express.createServer();
var reports = {};


function reapOldReports() {
  logger.info('starting reap cycle on {} reports', _.keys(reports).length);
  _.each(_.keys(reports), function(key) {
    var report = reports[key];
    var age = Math.round(((new Date()).getTime() - report.reported)/1000);
    if (age >= config.reapAge) {
      logger.info('reaping stale report for: {}:{}', report.host, report.port);
      delete reports[key];
    }
  });
}

poller.emitter.on('report', function(report) {
  var key = report.host + ':' + report.port;
  reports[key] = report;
});

app.configure(function() {
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express.static(__dirname + '/pages', { maxAge: 60*60 }));
    app.use(express.static(__dirname + '/static', { maxAge: 3*24*60*60 }));
});

app.configure(function(){
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.get('/reports', function(req, res) {
  res.setHeader('Content-Type', 'application/json');
  res.setHeader('Cache-Control', 'public, max-age=' + 10);
  res.send(JSON.stringify(reports));
  res.end();
});

logger.info('starting web UI on port: {}', config.httpPort)
app.listen(config.httpPort);
poller.startPollingMasterServer();
setInterval(reapOldReports, config.reapInterval*1000);
{'fraction_non_alphanumeric': 0.1936108422071636, 'fraction_numerical': 0.013552758954501452, 'mean_word_length': 4.70902394106814, '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': '837615', 'n_tokens_mistral': 1043, 'n_tokens_neox': 987, 'n_words': 193}