<commit_before>import fs from 'fs';
import path from 'path';
import http2 from 'http2';
import winston from 'winston';
import Koa from 'koa';
import koaCompress from 'koa-compress';
import koaHelmet from 'koa-helmet';
import koaStatic from 'koa-static';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { StaticRouter } from 'react-router-dom';

import getPosts from '../shared/assets/posts';
import App from '../shared/components/App';
import {
  cacheMaxAge,
  httpsPort,
  httpsMaxAge,
  pems,
  port,
} from '../../configuration';

winston.add(new winston.transports.Console());
winston.format.cli();
const listen = portToListen => (error) => {
  if (error) {
    winston.error(error);
  } else {
    winston.info(`Listening on port ${portToListen}`);
  }
};

const index = fs.readFileSync(path.resolve(__dirname, '..', 'public', 'index.html')).toString();
const key = fs.readFileSync(pems.key);
const cert = fs.readFileSync(pems.cert);

const app = new Koa();
const secureApp = new Koa();
const httpsApp = http2.createSecureServer({ key, cert }, secureApp.callback());

(async () => {
  const posts = await getPosts();

  app.use(ctx => ctx.redirect(`https://${ctx.host}${ctx.path}`));
  app.listen(port, listen(port));

  secureApp.use(koaCompress({ threshold: 0 }));
  secureApp.use(koaHelmet.hsts({ maxAge: httpsMaxAge, includeSubdomains: true }));
  secureApp.use(koaStatic('public', { index: false, maxAge: cacheMaxAge }));
  secureApp.use((ctx) => {
    const context = {};
    const root = renderToStaticMarkup((
      <StaticRouter location={ctx.url} context={context}>
        <App posts={posts} />
      </StaticRouter>
    ));

    if (context.url) {
      ctx.status = 301;
      ctx.redirect(context.url);
    } else {
      ctx.status = 200;
      ctx.body = index.replace('<!-- root -->', root);
    }
  });

  httpsApp.listen(httpsPort, listen(httpsPort));
})();<commit_msg>Log error messages<commit_after>import fs from 'fs';
import path from 'path';
import http2 from 'http2';
import winston from 'winston';
import Koa from 'koa';
import koaCompress from 'koa-compress';
import koaHelmet from 'koa-helmet';
import koaStatic from 'koa-static';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { StaticRouter } from 'react-router-dom';

import getPosts from '../shared/assets/posts';
import App from '../shared/components/App';
import {
  cacheMaxAge,
  httpsPort,
  httpsMaxAge,
  pems,
  port,
} from '../../configuration';

winston.add(new winston.transports.Console());
winston.format.cli();
const listen = portToListen => (error) => {
  if (error) {
    winston.error(error);
  } else {
    winston.info(`Listening on port ${portToListen}`);
  }
};

const index = fs.readFileSync(path.resolve(__dirname, '..', 'public', 'index.html')).toString();
const key = fs.readFileSync(pems.key);
const cert = fs.readFileSync(pems.cert);

const app = new Koa();
const secureApp = new Koa();
const httpsApp = http2.createSecureServer({ key, cert }, secureApp.callback());

(async () => {
  const posts = await getPosts();

  app.use(ctx => ctx.redirect(`https://${ctx.host}${ctx.path}`));
  app.listen(port, listen(port));

  secureApp.use(koaCompress({ threshold: 0 }));
  secureApp.use(koaHelmet.hsts({ maxAge: httpsMaxAge, includeSubdomains: true }));
  secureApp.use(koaStatic('public', { index: false, maxAge: cacheMaxAge }));
  secureApp.use((ctx) => {
    const context = {};
    const root = renderToStaticMarkup((
      <StaticRouter location={ctx.url} context={context}>
        <App posts={posts} />
      </StaticRouter>
    ));

    if (context.url) {
      ctx.status = 301;
      ctx.redirect(context.url);
    } else {
      ctx.status = 200;
      ctx.body = index.replace('<!-- root -->', root);
    }
  });

  secureApp.on('error', error => winston.error(error));

  httpsApp.listen(httpsPort, listen(httpsPort));
})();
{'fraction_non_alphanumeric': 0.17276422764227642, 'fraction_numerical': 0.00508130081300813, 'mean_word_length': 4.047435897435897, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, 'https://': 2, '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': '5176638', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1288, 'n_words': 301}