<commit_before>'use strict';

if(!process.env.NODE_ENV) process.env.NODE_ENV = 'dev';
var env = process.env.NODE_ENV;

var koa = require('koa');
var jade = require('koa-jade');
var serve = require('koa-static');
var compress = require('koa-gzip');
var conditional = require('koa-conditional-get');
var etag = require('koa-etag');
var fs = require('fs');

var logger = require('./logger');

var app = koa();
app.use(compress());

app.use(function* (next) {
  this.response.vary('Accept-Encoding');
  yield next;
});

app.use(conditional());
app.use(etag());

// delay to test some network stuff
// app.use(function *delay(next) {
//   yield function(cb) {
//     setTimeout(cb, 1000);
//   };
//   yield next;
// });

app.use(jade.middleware({
  viewPath: __dirname+'/views',
  basedir: __dirname,
  pretty: env === 'dev',
  compileDebug: env === 'dev',
  noCache: env === 'dev'
}));

app.use(require('koa-trie-router')(app));

app.use(serve('./dist', {
  maxage: 1000 * 3600 * 24 * 5 // five days
}));

var fetchLatestPosts = require('./fetchBlog');

// to cache the result
var latestPosts;

var hasCritical = fs.existsSync(__dirname+'/css/critical.css');
var critical;
if(hasCritical) {
  critical = fs.readFileSync(__dirname+'/css/critical.css');
}

app.route('/')
.get(function *() {
  this.response.set('Cache-Control', `max-age= ${3600*12}`);
  yield this.render('index', {
    posts: latestPosts,
    critical: critical
  });
});

var port = process.env.PORT || 3000;

var retrievePosts = function* () {
  latestPosts = yield fetchLatestPosts();
  return latestPosts
};

require('co')(function*() {
  yield retrievePosts();

  // poll latest posts every hours
  setInterval(require('co')(retrievePosts), 1000 * 3600);

  app.listen(port, function(err) {
    if(err) {
      logger.fatal('Cannot start server', err);
      setTimeout(() => process.exit(1) , 200);
      return;
    }
    logger.info('Server listening on port %d with env %s', port, env);
  });<commit_msg>No caching for the index page<commit_after>'use strict';

if(!process.env.NODE_ENV) process.env.NODE_ENV = 'dev';
var env = process.env.NODE_ENV;

var koa = require('koa');
var jade = require('koa-jade');
var serve = require('koa-static');
var compress = require('koa-gzip');
var conditional = require('koa-conditional-get');
var etag = require('koa-etag');
var fs = require('fs');

var logger = require('./logger');

var app = koa();
app.use(compress());

app.use(function* (next) {
  this.response.vary('Accept-Encoding');
  yield next;
});

app.use(conditional());
app.use(etag());

// delay to test some network stuff
// app.use(function *delay(next) {
//   yield function(cb) {
//     setTimeout(cb, 1000);
//   };
//   yield next;
// });

app.use(jade.middleware({
  viewPath: __dirname+'/views',
  basedir: __dirname,
  pretty: env === 'dev',
  compileDebug: env === 'dev',
  noCache: env === 'dev'
}));

app.use(require('koa-trie-router')(app));

app.use(serve('./dist', {
  maxage: 1000 * 3600 * 24 * 5 // five days
}));

var fetchLatestPosts = require('./fetchBlog');

// to cache the result
var latestPosts;

var hasCritical = fs.existsSync(__dirname+'/css/critical.css');
var critical;
if(hasCritical) {
  critical = fs.readFileSync(__dirname+'/css/critical.css');
}

app.route('/')
.get(function *() {
  yield this.render('index', {
    posts: latestPosts,
    critical: critical
  });
});

var port = process.env.PORT || 3000;

var retrievePosts = function* () {
  latestPosts = yield fetchLatestPosts();
  return latestPosts
};

require('co')(function*() {
  yield retrievePosts();

  // poll latest posts every hours
  setInterval(require('co')(retrievePosts), 1000 * 3600);

  app.listen(port, function(err) {
    if(err) {
      logger.fatal('Cannot start server', err);
      setTimeout(() => process.exit(1) , 200);
      return;
    }
    logger.info('Server listening on port %d with env %s', port, env);
  });
{'fraction_non_alphanumeric': 0.19212074699411613, 'fraction_numerical': 0.017395753389613713, 'mean_word_length': 4.00640204865557, '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': '7337709', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1322, 'n_words': 306}