flask-router
Routing system for node.js/connect based on Flask(http://flask.pocoo.org/).
Installation
npm install flask-router
Usage
var http = router = server = http;
It can also be used as a connect/express middleware:
var connect = app = router = app;
Then routes can be added like this:
router; router; router;
Can assign multiple handler functions to the same rule:
router; router;// All three handlers will be executed when the url match, so the final// response will be 'part1part2part3'
Custom parameter parsers can be registered(these are known as 'converters' in Flask/Werkzeug):
router; router;// If '/queryable/gt=5/lt=10/limit=20' was requested,// the output would be {"limit":"20","gt":"5","lt":"10"}
Can be used to write middlewares, just like express routes:
// anyone can access public filesrouter; // will match any path that starts with /privaterouterall'/private/<path:path>' { if reqheaders'x-user' reqloggedIn = true; ; else ; };routerall'/private/<path:path>' { res; // not authorized res;}; // the next two handlers will only be executed if the user is// authorized(in this case, the request must have x-user header)router; router
RegExps can also be used as rules:
router
See tests for more examples.