Skip to content
New issue

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

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
arxpoetica opened this issue Jan 17, 2013 · 1 comment
Open

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

arxpoetica opened this issue Jan 17, 2013 · 1 comment

Comments

@arxpoetica
Copy link

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
Copy link
Owner

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) {
            next(req)
        } 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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants