<commit_before>module.exports = (entry, options={}) ->
  maxAge = options.maxAge or 0
  bundle = null

  middleware = (req, res, next) ->
    unless bundle?
      require('./bundle') entry, options, (err, _bundle) ->
        bundle = _bundle
        middleware req, res, next
      return

    url = req.url.replace /\.\w+$/, ''

    unless (mod = bundle.find url)?
      return next()

    now = new Date().toUTCString()
    res.setHeader 'Date', now unless res.getHeader 'Date'<commit_msg>Slightly more robust parsing of url in middleware.<commit_after>{parse} = require 'url'

module.exports = (options={}) ->
  unless options.entry?
    throw new Error 'Entry module unspecified'

  maxAge = options.maxAge or 0
  bundle = null

  middleware = (req, res, next) ->
    unless bundle?
      require('./bundle') options.entry, options, (err, _bundle) ->
        bundle = _bundle
        middleware req, res, next
      return

    # parse url to deal with oddness
    url  = parse req.url, true, true

    # strip extension from module path
    path = url.pathname.replace /\.\w+$/, ''

    unless (mod = bundle.find path)?
      return next()

    now = new Date().toUTCString()
    res.setHeader 'Date', now unless res.getHeader 'Date'
{'fraction_non_alphanumeric': 0.1308562197092084, 'fraction_numerical': 0.0016155088852988692, 'mean_word_length': 2.6441176470588235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5793119', 'n_tokens_mistral': 388, 'n_tokens_neox': 363, 'n_words': 122}