# File lib/nanoc/extra/auto_compiler.rb, line 34
    def call(env)
      @mutex.synchronize do
        # Start with a new site
        build_site

        # Find rep
        path = Rack::Utils::unescape(env['PATH_INFO'])
        reps = site.items.map { |i| i.reps }.flatten
        rep = reps.find do |r|
          r.path == path ||
            r.raw_path == site.config[:output_dir] + path
        end

        # Recompile
        site.compile if rep

        # Get paths by appending index filenames
        if path =~ /\/$/
          possible_paths = site.config[:index_filenames].map { |f| path + f }
        else
          possible_paths = [ path ]
        end

        # Find matching file
        modified_path = possible_paths.find { |f| File.file?(site.config[:output_dir] + f) }
        modified_path ||= path

        # Serve using Rack::File
        puts "*** serving file #{modified_path}"
        res = file_server.call(env.merge('PATH_INFO' => modified_path))
        puts "*** done serving file #{modified_path}"
        res
      end
    rescue StandardError, ScriptError => e
      # Add compilation stack to env
      env['nanoc.stack'] = []
      stack.reverse.each do |obj|
        if obj.is_a?(Nanoc::ItemRep) # item rep
          env['nanoc.stack'] << "[item] #{obj.item.identifier} (rep #{obj.name})"
        else # layout
          env['nanoc.stack'] << "[layout] #{obj.identifier}"
        end
      end

      # Re-raise error
      raise e
    end