<commit_before>const express = require('express')
const path = require('path')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

const i18nextMiddleware = require('i18next-express-middleware')
const Backend = require('i18next-node-fs-backend')
const i18n = require('./lib/i18n')

i18n
  .use(Backend)
  .use(i18nextMiddleware.LanguageDetector)
  .init({
    preload: ['en', 'fr'],
    defaultNS: 'common',
    ns: [
      'common',
      'home',
      'catalogs'
    ],
    backend: {
      loadPath: path.join(__dirname, '/locales/{{lng}}/{{ns}}.json'),
      addPath: path.join(__dirname, '/locales/{{lng}}/{{ns}}.missing.json')
    },
    detection: {
      lookupCookie: 'locale'
    }
  }, () => {
    app.prepare()
      .then(() => {
        const server = express()

        server.use((req, res, next) => {
          if (req.url.length > 1 && req.url.substr(-1) === '/') {
            return res.redirect(301, req.url.slice(0, -1))
          }
          next()
        })
        server.use(i18nextMiddleware.handle(i18n))

        server.use('/locales', express.static(path.join(__dirname, '/locales')))

        if (dev) {
          server.post('/locales/add/:lng/:ns', i18nextMiddleware.missingKeyHandler(i18n))
        }

        server.get('/catalogs/:id', (req, res) =>
          app.render(req, res, '/catalog', Object.assign(req.query, {
            id: req.params.id
          }))
        )
<commit_msg>Do not redirect next internal urls<commit_after>const express = require('express')
const path = require('path')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

const i18nextMiddleware = require('i18next-express-middleware')
const Backend = require('i18next-node-fs-backend')
const i18n = require('./lib/i18n')

i18n
  .use(Backend)
  .use(i18nextMiddleware.LanguageDetector)
  .init({
    preload: ['en', 'fr'],
    defaultNS: 'common',
    ns: [
      'common',
      'home',
      'catalogs'
    ],
    backend: {
      loadPath: path.join(__dirname, '/locales/{{lng}}/{{ns}}.json'),
      addPath: path.join(__dirname, '/locales/{{lng}}/{{ns}}.missing.json')
    },
    detection: {
      lookupCookie: 'locale'
    }
  }, () => {
    app.prepare()
      .then(() => {
        const server = express()

        server.use((req, res, next) => {
          if (req.url.length > 1 && !app.isInternalUrl(req.url) && req.url.substr(-1) === '/') {
            return res.redirect(301, req.url.slice(0, -1))
          }
          next()
        })
        server.use(i18nextMiddleware.handle(i18n))

        server.use('/locales', express.static(path.join(__dirname, '/locales')))

        if (dev) {
          server.post('/locales/add/:lng/:ns', i18nextMiddleware.missingKeyHandler(i18n))
        }

        server.get('/catalogs/:id', (req, res) =>
          app.render(req, res, '/catalog', Object.assign(req.query, {
            id: req.params.id
          }))
        )

{'fraction_non_alphanumeric': 0.1833855799373041, 'fraction_numerical': 0.0219435736677116, 'mean_word_length': 2.5534521158129175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1935405', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1052, 'n_words': 188}