Created
January 21, 2012 01:32
-
-
Save tobyhede/1650665 to your computer and use it in GitHub Desktop.
Ideas for light-weight node middleware functions
This file contains 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
/* | |
Ideas for light-weight node middleware functions | |
Riffing on ideas for weaving functions together in a middleware architecture for node. | |
Overview: | |
a function that returns a rack-style array of status, headers and body | |
Function Requirements: | |
access to the environment (essentially the raw node request and response objects) | |
access to the output array of any middleware higher in the stack | |
Writing these down, I currently like Option 2, but not 100% convinced. | |
*/ | |
// option 1 | |
// out is the current output array of the stack | |
function hello(out) { | |
var env = this.env; | |
return [200, {"Content-Type": "text/plain"}, "hello"] | |
} | |
// option 2 | |
// receive the current stack as individual parameters | |
function hello(status, headers, body) { | |
var env = this.env; | |
return [200, {"Content-Type": "text/plain"}, "hello"] | |
} | |
// option 3 | |
// no parameters, access via this | |
function hello() { | |
var env = this.env; | |
var out = this.out; | |
return [200, {"Content-Type": "text/plain"}, "hello"] | |
} | |
// option 4 | |
// no parameters, but this has individual properties for the current output | |
function hello() { | |
var env = this.env; | |
var status = this.status; | |
return [200, {"Content-Type": "text/plain"}, "hello"] | |
} | |
// option 5 | |
// both env and out are parameters | |
function hello(env, out) { | |
return [200, {"Content-Type": "text/plain"}, "hello"] | |
} | |
// option n? | |
// better ideas? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment