mcavage/node-restify — pull request #351 by sislab (2013-03-18 12:13:48+00:00)
Title: plugins/static.js serveStatic - opts.subst() for file location control.

This patch is useful for users that want static location control. Here is the problem. If req.path() is /test then static files must be in ./public/test and i'm in situation where it's not possible to create dirs or move files around. In the other words, all html files are placed in ./public. So if i use path other then '/' serving static file is not possible. Solution is this onliner patch:

How to use it:

server.get(regx, restify.serveStatic({
directory: './public',
subst: function(rpath) {
var match = rpath.match(new RegExp('^(' + url + ')' + '\/(.*)'));

if(match && 3 === match.length) {
return match[2];
}

return null;
}
}))

subst argument (rpath) is req.path() so method should be safe.
Method returns new path that will reside inside './public' and will be used to find files.

What do you think?