Completely agree that not having the default action at the end would cause 
issues in a single middleware stack.

I use middleware trees rather than single stack with Understudy, it would 
go to the end of an action (for example the default action such as just 
closing the HTTP request). I run into this problem a fair amount when 
making pluggable servers. For example:

```javascript
server.before('http.auth', databaseLogin)
server.before('http.auth', googleLogin)
server.before('http.auth', twitterLogin)
server.before('http.auth', anonymousLogin)
```

If one of these passes, we want to skip to the end of the 'http.auth' 
action. This gets even more complicated when you start using trees (example 
from an existing code base [sorry for the inlining]):

```javascript
server.perform('http.auth', req, res, function (err, req, res) {
  // default action if middleware do not pick it up
  // people can listen on('end') if they really want to do odd things out 
of band with the req / res
  function finish(err, req, res) {
    res.writeHead(404); res.end()
  }
  // use apt middleware for state and just let them route if able
  if (req.authorization) {
    server.perform('http.authorized-request', req, res, finish);
  }
  else {
    server.perform('http.unauthorized-request', req, res, finish);
  }
})
```

Notice in the above example I rely on middleware to not call next() if it 
can handle a behavior to absolute completion. I think this is just a 
documentation issue personally for actions, but feel free to disagree. 
Standardizing if a middleware is a leaf of the control flow vs node is 
something that is too complex to write in code.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to