Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created September 30, 2012 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/3808490 to your computer and use it in GitHub Desktop.
Save Raynos/3808490 to your computer and use it in GitHub Desktop.
Middleware
var HttpStream = require("http-stream")
, chain = require("chain-stream")
var server = chain(HttpStream().listen(3000))
var serverWithMiddleware = server
.map(function (duplex, callback) {
getSession(duplex, function (err, session) {
if (err) {
return callback(err)
}
callback(null, {
duplex: duplex
, session: session
})
})
})
serverWithMiddleware
.filter(function (duplex) {
return duplex.url === "/home"
})
.forEach(function (duplex) {
duplex.end(homePageTemplate)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment