how can I modify or replace the directory index page in Express?

In express, I can something like this to have a static server, with directory index pages:

app.configure(function() {
    app.use('/mystuff', _express.static(__dirname + "/whatever/stuff"));
    app.use('/mystuff', _express.directory(__dirname + "/whatever/stuff"));
});

I would like to modify the directory index pages, by giving them different css, adding some javascript, and maybe altering the html. I prefer use as much of the existing functionality if possible, but if it is easy to just replace the whole directory middleware with my own code, that's an option. Not sure where to start with this. Of course, I don't want to actually edit code in the express or connect modules.

BTW, one reason for this is to workaround a bug I mentioned here: How do I set up static serving in Express with an arbitrary start path?

As you said in your comment, the express.directory functionality comes from Connect middleware; however, there doesn't seem to be a way to set a custom file.

As an alternative solution, you could fork Connect, change the files (located at lib/public/directory.html and lib/public/style.css), use your fork as a dependency, and do:

var connect = require('connect');

app.configure(function() {
    app.use('/mystuff', connect.static(__dirname + "/whatever/stuff"));
    app.use('/mystuff', connect.directory(__dirname + "/whatever/stuff"));
});

Instead of the express ones. I just tested this (by editing the files in node_module), and it worked.

EDIT: Actually, you could probably just grab directory.js from connect and modify it and put it in your app and require() it, and then use yours instead. I haven't tested this, but I can't see why it wouldn't work.