Express.js Routes Explanation
I was looking at express.js source code, to find out how it maps named route parameters to req.params properties. For those who don't know, in express.js you can define routes wit
Solution 1:
It is for matching file extensions and such properly.
Given the path '/path/:file.:ext'
, consider the difference between the expressions:
// With 'format' checking
/^\/path\/(?:([^\/]+?))(?:\.([^\/\.]+?))\/?$/
// Without 'format' checking
/^\/path\/(?:([^\/]+?))(?:([^\/]+?))\/?$/
In the first case, you end up with params as
{
file: 'file',
ext: 'js'
}
but without the format checking, you end up with this:
{
file: 'f',
ext: 'ile.js'
}
Post a Comment for "Express.js Routes Explanation"