Djurl is an attempt at providing Django URL dispatching for node.js.
- Simple action dispatching
- Familiar to Django users
- Supports Python regex named capture groups (e.g.
(?P<groupname>.*?))
URL dispatching is basic:
var djurl = require("djurl");
/* indexAction and fooAction functions */
/* Define patterns */
var patterns = djurl.urlpatterns([
["^/$", indexAction, "index"],
["^/foo/(?P<action>\\w+)/$", fooAction],
]);
http.createServer(function(req, res) {
djurl.dispatch(patterns, req, res); /* url processing starts here */
}).listen(8080);
urlpatterns accepts an array of pattern arrays with the following format:
path- String containing path to compile to RegExpaction- Function to dispatch on matching pathname(Optional) - String containing named handle to url pattern
Actions should accept the following arguments:
request- Node request objectresponse- Node response handlepath- Object containing path infoname- String containing path name defined inurlpatterns
- Make sure Regex character classes are escaped properly:
\\w+instead of\w+
- Better 404 handling
- Robustness
- Performance
- Extend Node request object?
The MIT License
Copyright © 2011 Chris Bennett [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.