Support for RegEx paths
Aurelsicoko opened this issue · comments
Do you plan to support path string such as /user/:id
? Using this library for example https://github.com/pillarjs/path-to-regexp
Yes. I've updated readme.md to let everyone know how to write routes.
There are 3 types of routes:
1.Static
Pattern: /static
/static match
/anything-else no match
2.Named
Named parameters have the form :name
and only match a single path segment:
Pattern: /user/:user
/user/gordon match
/user/you match
/user/gordon/profile no match
/user/ no match
3.Catch-all
Catch-all parameters have the form *name
and match everything. They must always be at the end of the pattern:
Pattern: /src/*filepath
/src/ match
/src/somefile.go match
/src/subdir/somefile.go match
This library use a tree data structure to represent routes. And that is the reason this library is much faster than koa-router, which is based on path-to-regexp
. Therefore I won't use path-to-regexp
.
Awesome! Thanks for the quick answer. I have another question, how the library deals with multiple middlewares per route?
const middleware = (ctx, next) => {
// Do stuff...
};
const action = (ctx, next) => {
ctx.send('ok');
};
router.get("/", [middleware, action]);
Is this possible?