Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Need for something like next() with .before #67

arxpoetica opened this Issue Jan 17, 2013 · 1 comment


None yet
2 participants

I have a case where it's taking me a little while to do something in the .before() request handler. Express.js's method for handling this kind of behavior is to either send a response or to call next(); I realize this might be a major feature request, but .before() is misleading because it doesn't actually wait to run any routes. It just does stuff sequentially, without any pause.

My example:

this.before(function (req) {
    // send a request to the server to see if user is authenticated
    // if user is authenticated, allow the route to continue (next())
    // if user is not authenticated, reroute them

The problem is, since it takes a split second to ping the server for this information (in my case, there's a reason to not just use local storage), IT ACTUALLY RENDERS THE ADMIN PAGE before rerouting. It's only a split second, but this is unfortunate. :(

Basically, 1) is there a next() concept in Davis.js, and 2) if not, why, and 3) can there be something like next() added?


olivernn commented Jan 17, 2013

Davis actually uses a very similar approach to express with route middleware. These are currently only at an individual route level but should acheive exactly what you are looking for.

var isAdmin = function (req, next) {
    checkForAdminRole(function (success) {
        if (success) {
        } else {
            // do whatever

this.get('/admin', isAdmin, function (req) {
    // admin related stuff in here

This is actually the direction I would like to get before filters to go, but this is a way of yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment