Comments (36)
Maybe need a recursion function likes printTree
.
from echo.
This test doesn't do much, I am working on to add conflicting routes and priority order to get picked up - it's not done yet. I am not even sure if that would be possible without giving up on the performance of the router. #16
from echo.
I'm looking forward. π
from echo.
Do you have plain to fix this?
from echo.
Deferred it until few more releases - it's getting complicated.
from echo.
Okay, I also try to fix this in my Node version.
There are some cases http://guides.rubyonrails.org/routing.html.
I think we should support them.
from echo.
Sure, thanks.
from echo.
I think we can convert any :param
to :$1
first, below like this:
/photos/:id => /photos/:$1
// alias = ['id']
/photos/:pid/users/:id => /photos/:$1/users/:$2
// alias = ['pid', 'id']
Convert the original path to format path and store the param keys.
from echo.
@fundon This is an interesting point, I never noticed it. I will implement it at next opportunity.
from echo.
@vishr I implement a version, and haven't been optimized, so currently it's very slower.
See
- https://github.com/trekjs/router/blob/refoctor/src/router.js
- https://github.com/trekjs/router/blob/refoctor/test/router.test.js test case
- https://travis-ci.org/trekjs/router/builds/
from echo.
@vishr I refactor the add()
, insert()
and find()
methods.
See
- https://github.com/trekjs/router/blob/master/src/router.js#L86
- https://github.com/trekjs/router/blob/master/src/router.js#L142
- https://github.com/trekjs/router/blob/master/src/router.js#L211
Convert paths to special format.
/:username/:repo/issues/:id
=> /:$0/:$1/issues/:$2
e.g:
/users/:id
=>/users/:$0
/users/:userId/photos/:id
=>/users/:$0/photos/:$1
/users/:uid/books/:bid
=>/users/:$0/books/:$
Note Make sure the param
node append to the end of the edges
.
Improve performance.
I found the has
key is unused in find
method.
find(method, path)
steps:
- search snode
- search pnode
- search cnode
Maybe I can submit a PR. hah
Example:
'/geocoder'
'/geocoder/new'
'/geocoder/edit'
'/geocoder/edit/email'
'/geocoder/edit/:item'
'/geocoder/any*'
'/geocoder/:action'
βββ /geocoder has=1 h=function edges=1
βββ / has=0 h=null edges=4
βββ edit has=1 h=function edges=1
β βββ / has=0 h=null edges=2
β βββ email has=1 h=function edges=0
β βββ :$0 has=0 h=function edges=0
βββ new has=1 h=function edges=0
βββ any has=3 h=null edges=1
β βββ * has=0 h=function edges=0
βββ :$0 has=0 h=function edges=0
from echo.
@fundon Great!
Has property gives us node information without looking up into findEdge function. Are you talking about improvement in the mentioned cases or in general - the current implementation of the router?
Also can you elaborate on what all features you have implemented so far in your router?
from echo.
Implemented features:
- Convert param key to special key, likes:
/:username/:repo/issues/:id
=>/:$0/:$1/issues/:$2
- named param multi aliases, likes:
/users/:id
,/users/:userId/photos/:id
=>/users/:$0
,/users/:$0/photos/:$1
Full cases https://github.com/trekjs/router/blob/master/test/router.test.js
from echo.
@fundon Excellent, I never realized it was just a step away. I would like to incorporate these changes into the router - I already did some. How do you compare your router to other nodejs routers? Have you done any comparison?
from echo.
Use GitHub API routes, compare with below:
- path-to-regexp
- route-recognizer
- route-trie
- routington
https://github.com/trekjs/router/blob/master/benchmarks/index.js
from echo.
@vishr See this https://travis-ci.org/trekjs/router#L710
from echo.
Cool, you should publish your results in nodejs forum, https://www.reddit.com/r/node etc.
from echo.
Yes, I should. haha
Looking forward to your implementation in Go.
from echo.
BTW, I do not use has
key in find
method, maybe it is not neededγ
from echo.
Yup, I am gonna take some time and refactor the router based on our discussion - that will cover the cleanup and other goodies ;)
from echo.
@vishr I fixed a bug.
You can see this change via: https://github.com/trekjs/router/compare/d702c01826771302156a5e949bdc66a75992d431...master?diff=unified&name=master
from echo.
from echo.
The bug is below:
Bug:
/users/:id
/users/:id/edit
r.find('/users') // will match `/users/:id`.
The right behavior is not found
.
It's fixed in my latest Node.js version.
from echo.
I will look into it. Can you try the below routes?
/users/new
/users/:id
Find /users/nnn
from echo.
I did not try that.
from echo.
Wouldn't it go to new? as n comes first in the search?
from echo.
Should match /users/:id
.
from echo.
@fundon I tried below code, it returns empty.
var Router = require('trek-router');
r = new Router()
// static route
r.add('GET', '/users/new', {});
// param route
r.add('GET', '/users/:id', {});
// catch-all route
r.add('GET', '/books/*', {});
result = r.find('GET', '/users/nnn')
console.log(result)
from echo.
Yes, it's a bug. I'm thinking. How to fix this?
from echo.
I need some time to fix it.
from echo.
Me too. Good catch! Hah
from echo.
Wow, nice! π
There is not goto
statement in JavaScript. π hah
from echo.
@vishr I tried the latest Echo, I found a small bug.
/users
/users/new
/users/:id/echo
/users/*
Find /users/echo/hello => empty // right, return /users/*
Find /users/echo => empty // right, return /users/*
from echo.
@fundon How have you implemented param name alias?
Thanks
from echo.
@vishr Yes, I implemented it.
https://github.com/trekjs/router/blob/master/src/router.js#L87-L121
Examples:
/users/:id/echo => /users/:/echo ['id']
/users/:user_id/photos/:id => /users/:/photos/: ['user_id', 'id']
from echo.
Thanks @fundon
from echo.
Related Issues (20)
- Add an AllowContentType middleware (based on chi)
- Bind() panics when the destination is a map with non-interface types HOT 1
- Add SSE function in Context.Response HOT 7
- Any software design issues HOT 1
- Request support for more routing path matching HOT 1
- Unable to use proxy middleware along with bodyDump middleware HOT 1
- `Host` header always blank HOT 6
- Does echo support i18n? [feature request] HOT 2
- Weirdness with wrapped handler and embed FS (static files) HOT 1
- Remove default charset from 'application/json' Content-Type header
- echo v4 websocket client closed, program exited HOT 3
- router not setting ContextKeyHeaderAllow for group, causing cors preflight to not work HOT 6
- Static file has wrong body returned when using a custom HTTP Error Handler and complex paths HOT 2
- QueryParams seem to override formValues HOT 3
- DefaultHTTPErrorHandler does not log HOT 3
- Support Casbin Authorization Middleware HOT 1
- Echo response object calls flush on unflushable objects HOT 7
- Feature request: support Yaml responses transparently. HOT 1
- static middleware: path ist unescaped twice for file names, leading to not downloadable content
- CSRF middleware form lookup consumes all the request body HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from echo.