<commit_before>var express = require('express'),
    app = express(),
    cors = require('cors'),
    compression = require('compression'),
    Repository = require('./lib/db'),
    dotenv = require('dotenv');

// load vars
dotenv.load();


app.use(compression());
app.use(cors());

app.use(function(req, res, next) {
  req.repo = new Repository(process.env.DATABASE_URL);
  next();
});

app.get('/', function(req, res) {
  req.repo.getAll()
    .then(function(results) {
      var filtered = results.filter(function(mod) {
        // Skip modules with {"emberAddon": {"private": true}} on package.json
        if (!(typeof mod.doc.emberAddon !== 'undefined' &&
            typeof mod.doc.emberAddon.private !== 'undefined' &&
            mod.doc.emberAddon.private === true)) {
          return mod;
        }
      });

      res.json(filtered);
      req.repo.db.close();
    })
    .catch(function(err) {
      console.error(err);
      res.status(500).json({error: 'error'});
      req.repo.db.close();
    });
});

app.get('/stats', function(req, res) {
  req.repo.getMetric('total')
    .then(function(rows) {
      res.json(rows);
      req.repo.db.close();
    })
    .catch(function(err) {
      console.error(err);
      res.status(500).json({error: 'error'});
      req.repo.db.close();
    });
});


app.listen(process.env.PORT, function() {
  console.log('listening on port %d', process.env.PORT);
});<commit_msg>Redirect requests to /<commit_after>var express = require('express'),
    app = express(),
    cors = require('cors'),
    compression = require('compression'),
    Repository = require('./lib/db'),
    dotenv = require('dotenv');

// load vars
dotenv.load();


app.use(compression());
app.use(cors());

app.use(function(req, res, next) {
  req.repo = new Repository(process.env.DATABASE_URL);
  next();
});

app.get('/', function(req, res) {
  res.redirect(301,
    'https://io-builtwithember-addons-data.s3.amazonaws.com/addons.json');
});

app.get('/stats', function(req, res) {
  req.repo.getMetric('total')
    .then(function(rows) {
      res.json(rows);
      req.repo.db.close();
    })
    .catch(function(err) {
      console.error(err);
      res.status(500).json({error: 'error'});
      req.repo.db.close();
    });
});


app.listen(process.env.PORT, function() {
  console.log('listening on port %d', process.env.PORT);
});
{'fraction_non_alphanumeric': 0.20346869712351945, 'fraction_numerical': 0.005499153976311337, 'mean_word_length': 3.056603773584906, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '3537885', 'n_tokens_mistral': 813, 'n_tokens_neox': 798, 'n_words': 130}