redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Allow @Route to match sub paths #5

Closed y12studio closed 10 years ago

y12studio commented 10 years ago

This PR for the urlTemplate.match().tail.isNotEmpty with app.Route(r'/match/.*').

luizmineo commented 10 years ago

Thanks for pointing me this out. It seems bloodless can't properly handle regex expressions in @Route.

Unfortunately, just removing the tail.isNotEmpty check will not fix it. This check was added to guarantee the precedence of routes according to its path. For example, consider the following services:

@app.Route('/foo')
serviceA() {
  ...
}

@app.Route('/foo/bar/:param')
serviceB(String param) {
  ...
}

Without the check, if a request for /foo/bar/test is received, the result will be unpredictable, since UrlMatch will return a match for both routes.

I will have to change the route handling implementation, to guarantee that routes are always tested in the correct order (according to its path).

y12studio commented 10 years ago

@luizmineo you are right. looking forward to your new implementation.

luizmineo commented 10 years ago

After thinking about this problem, I figured out that would be impracticable to accept regex expression in @Route annotations :(

Although, I changed the route handling implementation to allow @Route to match subpaths. Example:

@app.Route('/path', matchSubPaths: true)
service() {
 ...
}

@app.Route('/path/subpath')
serviceB() {
 ...
}

So, if a request for /path/subpath is received, then serviceB is executed, but if a request for /path/another_path is received, service is executed.