fun-chain

0.1.0 • Public • Published

All aboard the fun train chain!

Pass arguments through a chain of functions. Each function must decide whether to continue through the chain.

 
var server = http.createServer(chain(
  [ dispatch('get', '/oauth-callback', oauthCallbackAction)
  , authenticateFromToken
  , servePrivateFiles
  , function(_,_, res) { notFound(res) }
  ]))
 
// ...
 
function authenticateFromToken(next, req, res) {
  validateAuthToken(
    authTokenFrom(req),
    withErrHandler(handleAuthTokenErr, function(isValid) {
      if (isValid) next(req, res) else redirectTo(res, oauth.authUrl(req.url))
    })
  })
}
 
// ...
 
function notFound(res) {
  res.writeHead(404)
  res.end("Not found\n")
}
 

It's like connect but without all the code

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i fun-chain

      Weekly Downloads

      1

      Version

      0.1.0

      License

      MIT

      Last publish

      Collaborators

      • quackingduck