0

I'm trying to build a simple searching/browsing service for a server and I thought it could be interesting to use Express for that to get familiar with it.

For the problem I'm considering, I have express@3.4.1 and a very simple app.js:

var express = require("express");
var app = express();
//var express = require('express')
//, app = express.createServer();

app.configure(function() {
    var hourMs = 1000*60*60;
    app.use(express.static(__dirname + '/public', { maxAge: hourMs }));
    app.use(express.directory(__dirname + '/public', {hidden: true, icons: true}));
    app.use(express.errorHandler());
});

app.listen(1333);

How can I style/customize the HTML/CSS that the directory middleware produces?

Should I overwrite express.directory.html in my app.js or is there a better/cleaner way?

Edit: After looking at the code it seems overriding the function is not the way to go. The file it uses seems rather hard-coded and I may end up copying the whole file to override what I want. So, any idea?

rgettman
  • 176,041
  • 30
  • 275
  • 357
Jérémie Parker
  • 3,184
  • 2
  • 20
  • 33

2 Answers2

1

You could extract all relevant code from the Express middleware, make your own adjustments, and save it as part of your app (as ./lib/middleware/directory.js or something).

If you're going to modify the files inside the node_modules/ directory you can be sure that you'll lose any modifications when you update.

You could rewrite express.directory.html(), but you might still run into the problem that any updates make it stop working because of internal changes.

robertklep
  • 198,204
  • 35
  • 394
  • 381
0

I believe directly editing the node_modules/express/node_modules/connect/lib/public/style.css and directory.html would be the cleanest way of customizing the default express directory style/html.

enducat
  • 1,676
  • 3
  • 17
  • 16