Skip to content

Instantly share code, notes, and snippets.

@guybrush
Created September 14, 2010 17:21
Show Gist options
  • Save guybrush/579402 to your computer and use it in GitHub Desktop.
Save guybrush/579402 to your computer and use it in GitHub Desktop.
app.get(/^\/foo\/(.+)/, function(req, res) {
var encoding = (/[.png]+$/.test(req.params[0])) ? 'binary' : 'utf-8';
var path = '/foo/'+req.params[0];
fs.readFile(path, encoding, function(err, data) {
if (err) {
throw err;
} else {
res.contentType(req.params[0]);
res.send(data);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment