<commit_before>#!/usr/bin/env node

const compression = require('compression')
const express = require('express')
const helmet = require('helmet')
const { access } = require('fs')
const { parsePath } = require('history/PathUtils')
const { resolve } = require('path')

const { kaliber: { serveMiddleware, helmetOptions } = {} } = (process.env.CONFIG_ENV ? require('@kaliber/config') : {})

const app = express()

const target = resolve(process.cwd(), 'target')
const index = resolve(target, 'index.html.js')
const notFound = resolve(target, '404.html')
const internalServerError = resolve(target, '500.html')

const port = process.env.PORT
const isProduction = process.env.NODE_ENV === 'production'

// hsts-headers are sent by our loadbalancer
app.use(helmet(Object.assign({ hsts: false }, helmetOptions)))
app.use(compression())
serveMiddleware && app.use(serveMiddleware)
app.use(express.static(target))

app.use((req, res, next) => {
  fileExists(index)
    .then(fileFound => fileFound ? serveIndex(req, res, next) : next())
    .catch(next)
})

app.use((req, res, next) => {
  fileExists(notFound)
    .then(fileFound => fileFound ? res.status(404).sendFile(notFound) : next())
    .catch(next)
})

app.use((err, req, res, next) => {
  if (!err) return next()

  console.error(err)
  const response = res.status(500)
  if (isProduction) {
    fileExists(internalServerError)
      .then(() => response.sendFile(internalServerError))
      .catch(next)<commit_msg>Repair express middleware feature<commit_after>#!/usr/bin/env node

const compression = require('compression')
const express = require('express')
const helmet = require('helmet')
const { access } = require('fs')
const { parsePath } = require('history/PathUtils')
const { resolve } = require('path')

const { kaliber: { serveMiddleware, helmetOptions } = {} } = (process.env.CONFIG_ENV ? require('@kaliber/config') : {})

const app = express()

const target = resolve(process.cwd(), 'target')
const index = resolve(target, 'index.html.js')
const notFound = resolve(target, '404.html')
const internalServerError = resolve(target, '500.html')

const port = process.env.PORT
const isProduction = process.env.NODE_ENV === 'production'

// hsts-headers are sent by our loadbalancer
app.use(helmet(Object.assign({ hsts: false }, helmetOptions)))
app.use(compression())
serveMiddleware && app.use(...[].concat(serveMiddleware))
app.use(express.static(target))

app.use((req, res, next) => {
  fileExists(index)
    .then(fileFound => fileFound ? serveIndex(req, res, next) : next())
    .catch(next)
})

app.use((req, res, next) => {
  fileExists(notFound)
    .then(fileFound => fileFound ? res.status(404).sendFile(notFound) : next())
    .catch(next)
})

app.use((err, req, res, next) => {
  if (!err) return next()

  console.error(err)
  const response = res.status(500)
  if (isProduction) {
    fileExists(internalServerError)
      .then(() => response.sendFile(internalServerError))
      .catch(next)
{'fraction_non_alphanumeric': 0.16767676767676767, 'fraction_numerical': 0.00808080808080808, 'mean_word_length': 4.942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2717036', 'n_tokens_mistral': 963, 'n_tokens_neox': 945, 'n_words': 210}