Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
Change-Id: I5aff679a93b7f00b8963cc97bc38dfe1ad36e517
  • Loading branch information
creationix committed Dec 26, 2010
0 parents commit 8af8c4d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Empty file added README.markdown
Empty file.
Empty file added package.json
Empty file.
27 changes: 27 additions & 0 deletions stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

module.exports = function Stack(/*layers*/) {
function error(req, res, err) {
if (err) {
res.writeHead(500, {"Content-Type": "text/plain"});
res.end(err.stack + "\n");
return;
}
res.writeHead(404, {"Content-Type": "text/plain"});
res.end("Not Found\n");
}
var handle = error;
Array.prototype.slice.call(arguments).reverse().forEach(function (layer) {
var child = handle;
handle = function (req, res) {
try {
layer(req, res, function (err) {
if (err) { return error(req, res, err); }
child(req, res);
});
} catch (err) {
error(req, res, err);
}
};
});
return handle;
};

0 comments on commit 8af8c4d

Please sign in to comment.