baseprime / grapnel

The smallest JavaScript router with named parameters, HTML5 pushState, and middleware support
http://grapnel.js.org
467 stars 40 forks source link

Allow next() to be called from the last middleware in the stack (server side) #63

Closed ilearnio closed 5 years ago

ilearnio commented 8 years ago

Done same thing on the server so that when next() is called from the last middleware in the stack it will not throw. If no res.end() was specified in the last middleware it will be up to Express to finish the response.

The reason why I needed this feature is because I have many middlewares that are triggering next(), but they can be attached to the stack in a messy order (hooked up from different files). Even my very last middleware which prints the HTML to the browser contains next(). Which looks like so:

function(req, res, next) {
  // run all other middlewares (if any) before continuing the current one
  next()

  ...
  res.end('html')
}