dotcloud/hipache — pull request #40 by ubermuda (2013-08-15 03:10:16+00:00)
Title: Basic middleware support

Full disclosure: this is my first time ever messing with nodejs and all that serverside javascript stuff, so I'm still a bit confused about how `require` and package management works (also, async programming). This PR is not as much a PR as an RFC on how to improve that code (and also a "do you want middleware support in hipache?", question to which "no" would be a perfectly understandable answer). So if there's anything that could be done better, please let me know.

Another thing, I would to make module paths in the config.json relative to the config.json file itself. I'm not sure how to do that since nobody gets to know the config file's path except `bin/hipache` (which, honestly, is not helping in this particular case).

Following is the actual commit message:

Since configuring middleware requires to actually write code, I added a
simple mechanism to load custom pre-configured middleware. The
configuration file has a new `server.stack` setting and now looks like
that:

{
"server": {
// default stuff omitted for brevity

"stack": [
"/path/to/module.js"
]
}
}

I'm not sure how `require` actually works, so right now I'd recommend
having absolute paths.

Each configured module should export a function that takes two argument
(the Worker instance and the request) and must return an array of
middlewares, for example:

module.exports = function(worker, req) {
return [
function(req, res, next) {
console.log('Hi I\'m a painfuly useless middleware');
next();
}
];
});