<commit_before>import path from 'path';
import fs from 'mz/fs';
import express from 'express';
import mime from 'mime';
import getPreferredEncodings from 'negotiator/lib/encoding';
import compression from 'compression';
import cookiesMiddleware from 'universal-cookie-express';
import getWebpackSettings from '../../../shared/webpack-settings';
import argv from '../../../internals/rjs-argv';
import logger from '../../../shared/logger';
import { getDefault } from '../../../shared/util/ModuleUtil';

const webpackClientConfig = getWebpackSettings(/* is server */ false);
const httpStaticPath = webpackClientConfig.output.publicPath;
const fsClientOutputPath = webpackClientConfig.output.path;
const clientEntryPoint = path.join(fsClientOutputPath, 'index.html');

const HAS_PRERENDERING = argv.prerendering !== false;

function redirectToPreCompressed(root, encodingTransforms = {}) {
  root = path.resolve(root);
  const availableEncodings = Object.keys(encodingTransforms);

  return async function redirect(req, res, next) {
    // req.acceptsEncoding is not powerful enough, and creates a new instance of Accept AND Negociator
    // on every single call. negotiator/lib/encoding.getPreferredEncodings is a pure function, I'm going to use that.
    const encodings = getPreferredEncodings(req.header('Accept-Encoding'), availableEncodings);

    for (const encoding of encodings) {
      const transform = encodingTransforms[encoding];

      // '/test.js' => '/test.js.gz'
      const newPath = transform(req.path);

      // eslint-disable-next-line no-await-in-loop
      const exists = await fs.exists(path.join(root, newPath));
      if (!exists) {
        continue;
      }

      const originalUrl = req.url;
      req.url = transform(originalUrl);<commit_msg>feat: Disable SSR by default<commit_after>import path from 'path';
import fs from 'mz/fs';
import express from 'express';
import mime from 'mime';
import getPreferredEncodings from 'negotiator/lib/encoding';
import compression from 'compression';
import cookiesMiddleware from 'universal-cookie-express';
import getWebpackSettings from '../../../shared/webpack-settings';
import argv from '../../../internals/rjs-argv';
import logger from '../../../shared/logger';
import { getDefault } from '../../../shared/util/ModuleUtil';

const webpackClientConfig = getWebpackSettings(/* is server */ false);
const httpStaticPath = webpackClientConfig.output.publicPath;
const fsClientOutputPath = webpackClientConfig.output.path;
const clientEntryPoint = path.join(fsClientOutputPath, 'index.html');

const HAS_PRERENDERING = argv.prerendering === true;

function redirectToPreCompressed(root, encodingTransforms = {}) {
  root = path.resolve(root);
  const availableEncodings = Object.keys(encodingTransforms);

  return async function redirect(req, res, next) {
    // req.acceptsEncoding is not powerful enough, and creates a new instance of Accept AND Negociator
    // on every single call. negotiator/lib/encoding.getPreferredEncodings is a pure function, I'm going to use that.
    const encodings = getPreferredEncodings(req.header('Accept-Encoding'), availableEncodings);

    for (const encoding of encodings) {
      const transform = encodingTransforms[encoding];

      // '/test.js' => '/test.js.gz'
      const newPath = transform(req.path);

      // eslint-disable-next-line no-await-in-loop
      const exists = await fs.exists(path.join(root, newPath));
      if (!exists) {
        continue;
      }

      const originalUrl = req.url;
      req.url = transform(originalUrl);
{'fraction_non_alphanumeric': 0.12338392355255762, 'fraction_numerical': 0.0, 'mean_word_length': 4.0625889046941674, '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': '5758198', 'n_tokens_mistral': 1002, 'n_tokens_neox': 990, 'n_words': 279}