<commit_before>import * as bodyParser from "body-parser";
import { EventEmitter } from "events";
import * as compression from "compression";
import * as cors from "cors";
import * as exphbs from "express-handlebars";
import * as express from "express";
import * as helmet from "helmet";
import * as serveStatic from "serve-static";

import WebServerConfig from "./WebServerConfig";

import apiRoutes from "./routes/api";
import catchAllRoutes from "./routes/catchAll";
import feedRouter from "./routes/feed";
import healthRoutes from "./routes/health";
import indexRoutes from "./routes/index";

import templateHelpers from "./templateHelpers";

class WebServer extends EventEmitter {
  private server?: any;

  constructor (private config: WebServerConfig) {
    super();

    this.config = config;
    this.server = null;
  }

  private createHandlebars (): Exphbs {
    return exphbs.create({
      defaultLayout: "main",
      helpers: templateHelpers,
    });
  }

  public async start (): Promise<express.Application> {
    const app: express.Application = express();

    app.engine("handlebars", this.createHandlebars().engine);
    app.set("view engine", "handlebars");

    app.use(helmet());
    app.use(cors());
    app.use(compression());
    app.use(bodyParser.urlencoded({ extended: false }));

    app.use(healthRoutes());
    app.use(await indexRoutes());
    app.use(feedRouter());
    app.use(apiRoutes());
    app.use(serveStatic("public", {
      cacheControl: true,
      maxAge: "1d",
      setHeaders: (res: any) => {
        res.setHeader("Cache-Control", `public, max-age=${60 * 60 * 24}`);
      },
    }));

    // Catch all
    app.use(catchAllRoutes());
<commit_msg>Use cache of 365 days for static stuff<commit_after>import * as bodyParser from "body-parser";
import { EventEmitter } from "events";
import * as compression from "compression";
import * as cors from "cors";
import * as exphbs from "express-handlebars";
import * as express from "express";
import * as helmet from "helmet";
import * as serveStatic from "serve-static";

import WebServerConfig from "./WebServerConfig";

import apiRoutes from "./routes/api";
import catchAllRoutes from "./routes/catchAll";
import feedRouter from "./routes/feed";
import healthRoutes from "./routes/health";
import indexRoutes from "./routes/index";

import templateHelpers from "./templateHelpers";

class WebServer extends EventEmitter {
  private server?: any;

  constructor (private config: WebServerConfig) {
    super();

    this.config = config;
    this.server = null;
  }

  private createHandlebars (): Exphbs {
    return exphbs.create({
      defaultLayout: "main",
      helpers: templateHelpers,
    });
  }

  public async start (): Promise<express.Application> {
    const app: express.Application = express();

    app.engine("handlebars", this.createHandlebars().engine);
    app.set("view engine", "handlebars");

    app.use(helmet());
    app.use(cors());
    app.use(compression());
    app.use(bodyParser.urlencoded({ extended: false }));

    app.use(healthRoutes());
    app.use(await indexRoutes());
    app.use(feedRouter());
    app.use(apiRoutes());
    app.use(serveStatic("public", {
      cacheControl: true,
      maxAge: "365d",
      setHeaders: (res: any) => {
        res.setHeader("Cache-Control", `public, max-age=${60 * 60 * 24 * 365}`);
      },
    }));

    // Catch all
    app.use(catchAllRoutes());

{'fraction_non_alphanumeric': 0.14686131386861315, 'fraction_numerical': 0.006423357664233576, 'mean_word_length': 3.7320441988950277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1313933', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1027, 'n_words': 272}