Created
April 23, 2012 03:25
-
-
Save jed/2468665 to your computer and use it in GitHub Desktop.
prototype plugin pattern idea to make middleware less magical
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Request(req, res) { | |
this.upstream = request | |
this.downstream = response | |
} | |
Request.prototype = { | |
start: function() { | |
// kick off the default chain of handlers | |
}, | |
// other built-in methods | |
} | |
Request.prototype.myPlugin = function(next) { | |
// custom logic based on this.upstream / this.downstream | |
next() | |
} | |
require("http").createServer(function(req, res) { | |
new Request(req, res).start() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment