Understanding router.route().all()

870 views
Skip to first unread message

Matthew Nuzum

unread,
Apr 21, 2014, 9:58:40 PM4/21/14
to expre...@googlegroups.com
Hello, I'm experimenting with routing using the router.route function http://expressjs.com/4x/api.html#router.route

If I create a route like this all I get is an endlessly loading page:

router.route('/register')
.all(function(req, res, next) {
})
.get(function(req, res, next) {
var context = { title: 'Contact list'};
res.render('register', context);
})
.post(function(req, res, next) {
res.format({
'text/html': function() {
res.redirect('/contacts');
},
'application/json': function() {
res.send(context);
}
});
});


However, if I omit the .all() function, it works like I'd expect. The page loads quickly and I see my content.

I've been reading through the docs and I can't see a difference between what I've done and the example code. Any tips are greatly appreciated!

Matthew Nuzum

Paul Vencill

unread,
Apr 22, 2014, 7:14:38 PM4/22/14
to expre...@googlegroups.com

The all function gets called and never calls next() so the program doesn't know it's done working and hangs.

--
You received this message because you are subscribed to the Google Groups "Express" group.
To unsubscribe from this group and stop receiving emails from it, send an email to express-js+...@googlegroups.com.
To post to this group, send email to expre...@googlegroups.com.
Visit this group at http://groups.google.com/group/express-js.
For more options, visit https://groups.google.com/d/optout.

greelgorke

unread,
Apr 23, 2014, 2:28:04 AM4/23/14
to expre...@googlegroups.com
exactly. every route have to either call next() or respond to the client. otherwize node doesn't know when your function is done with the request and wait
Reply all
Reply to author
Forward
0 new messages