Chain together a list of functions
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
index.js
package.json
test.js

README.md

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