title: Using nodejs Connect's static server middleware to serve only a subdirectory
body: <p>I'm trying to build a webapp where:</p>
  
  <p><a href="http://mydomain.com/static/x.png" rel="nofollow">http://mydomain.com/static/x.png</a>  serves x.png as a static file using Connect's static middleware
  <a href="http://mydomain.com/other_stuff" rel="nofollow">http://mydomain.com/other_stuff</a>  does other stuff</p>
  
  <p>My directory structure is</p>
  
  <pre><code>start_server.coffee
  static/
      x.png
  </code></pre>
  
  <p>In start_server.coffee I have:</p>
  
  <pre><code>app = connect()
  app.use connect.staticCache()
  app.use connect.static(__dirname + '/static')
  
  app.use ...middleware that serves the dynamic parts of my app...
  
  app.listen 80
  </code></pre>
  
  <p>When I try <a href="http://mydomain.com/static/x.png" rel="nofollow">http://mydomain.com/static/x.png</a>, the request bypasses the static server and gets routed to the rest of my app.  I stepped through the code in a debugger and it looks like static is trying to lookup static/static/x.png instead of static/x.png.</p>
  
  <p>I was able to get it working by changing connect.static(_<em>dirname + '/static') to connect.static(</em>_dirname), but now it will serve stuff that's not in the static directory which is not good!</p>
  
  <p>What's the cleanest way of doing what I'm trying to do?  I could probably use Express's routing functionality, but I don't particularly want to use Express unless I have to, since the rest of my app handles routing its own way.</p>
  
  <p>Thanks!</p>