3 ms·
Probably makes it hard to do things in the right order. You'd have a separate array just to keep track of order that you'd be iterating every time. And express
by trevordixon 12y ago
Probably makes it hard to do things in the right order. You'd have a separate array just to keep track of order that you'd be iterating every time.
And express allows for more than one handler even for a static route.
app.get('/', function(req, res, next) { next(); });
app.get('/', function(req, res) { res.send(); });
- danudey 12y agoThis could be solved by having (internally) a map of { path: [handler 1, handler 2]}. That makes static path matching constant time, and static paths with multiple handlers iterate over the requests appropriately. This can be a little confusing, especially given that you'd be specifying static and non-static paths separately, but it could be argued that that is less confusing than some methods. For example, nginx's method allows you to define paths in any order, but checks routes matching regular expressions first in config order, then picks a static route by most specific match; IOW the order of your routes in nginx doesn't matter until you have regular expressions, in which case it is surprisingly critical some of the time and irrelevant the rest of the time. Breaking it up into 'regular expression routes (checked first)' and 'static routes (checked last)' could simplify things conceptually, but doubtlessly raises more usability issues as well.