<commit_before>const serve = require('serve/lib/server')
const relativePaths = require('./relative-paths')

// taken from serve cli!
process.env.ASSET_DIR = '/' + Math.random().toString(36).substr(2, 10)

module.exports = (cookieName) => {
  const baseURL = process.env.PUBLIC_URL || ''
  const uiPath = process.env.REACT_APP_BUILD
  const uiIgnored = [ '.DS_Store', '.git/', 'node_modules' ]
  let rootUrls = []

  route.buildRelativePaths = () => {
    return (
      relativePaths(uiPath)
      .then((urls) => { rootUrls = urls })
    )
  }

  return route

  function route (req, res) {
    if (cookieName && baseURL) {
      const cookieValue = encodeURIComponent(baseURL)
      const cookie = `${cookieName}=${cookieValue}; Path=/;`
      res.setHeader('Set-Cookie', cookie)
    }
    const uiFlags = { single: true, auth: !!process.env.SERVE_USER }
    const overrideUrl = rootUrls.find((x) => req.url.indexOf(x) !== -1)
    if (req.url.startsWith(baseURL)) req.url = req.url.slice(baseURL)
    if (overrideUrl) req.url = overrideUrl
    serve(req, res, uiFlags, uiPath, uiIgnored)
  }
}<commit_msg>Remove slash after baseUrl and make sure entire url is not removed<commit_after>const serve = require('serve/lib/server')
const relativePaths = require('./relative-paths')

// taken from serve cli!
process.env.ASSET_DIR = '/' + Math.random().toString(36).substr(2, 10)

module.exports = (cookieName) => {
  const baseURL = process.env.PUBLIC_URL || ''
  const uiPath = process.env.REACT_APP_BUILD
  const uiIgnored = [ '.DS_Store', '.git/', 'node_modules' ]
  let rootUrls = []

  route.buildRelativePaths = () => {
    return (
      relativePaths(uiPath)
      .then((urls) => { rootUrls = urls })
    )
  }

  return route

  function route (req, res) {
    if (cookieName && baseURL) {
      const cookieValue = encodeURIComponent(baseURL)
      const cookie = `${cookieName}=${cookieValue}; Path=/;`
      res.setHeader('Set-Cookie', cookie)
    }
    const uiFlags = { single: true, auth: !!process.env.SERVE_USER }
    const overrideUrl = rootUrls.find((x) => req.url.indexOf(x) !== -1)
    if (req.url.startsWith(baseURL) && req.url.length > baseUrl.length + 1) {
      req.url = req.url.slice(baseURL.length + 1)
    }
    if (overrideUrl) req.url = overrideUrl
    serve(req, res, uiFlags, uiPath, uiIgnored)
  }
}
{'fraction_non_alphanumeric': 0.15744315744315746, 'fraction_numerical': 0.006006006006006006, 'mean_word_length': 3.4, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1817963', 'n_tokens_mistral': 796, 'n_tokens_neox': 785, 'n_words': 167}