Skip to content

Instantly share code, notes, and snippets.

@jed
Created April 23, 2012 03:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jed/2468665 to your computer and use it in GitHub Desktop.
Save jed/2468665 to your computer and use it in GitHub Desktop.
prototype plugin pattern idea to make middleware less magical
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