title: How do I use a Rack middleware only for certain paths?
body: <p>I'd like to have <code>MyMiddleware</code> run in my Rack app, but only for certain paths.  I was hoping to use <code>Rack::Builder</code> or at least <code>Rack::URLMap</code>, but I can't quite figure out how.</p>
  
  <p>This is what I thought would work, but doesn't:</p>
  
  <pre><code># in my rackup file or Rails environment.rb:
  map '/foo' do
    use MyMiddleware, { :some =&gt; 'options' }
  end
  </code></pre>
  
  <p>Or, better yet, with a Regexp:</p>
  
  <pre><code>map /^foo/ do
    use MyMiddleware, { :some =&gt; 'options' }
  end
  </code></pre>
  
  <p>But <code>map</code> seems to demand an app at the end; it won't fall back on just passing control back to its parent.  (The actual error is "<code>undefined method 'each' for nil:NilClass</code>" from when Rack tries to turn the end of that <code>do...end</code> block into an <code>app</code>.)</p>
  
  <p>Is there a middleware out there that takes an array of middlewares and a path and only runs them if the path matches?</p>