Permalink
Browse files

V0.3.0

  • Loading branch information...
whoamicz committed Mar 25, 2013
1 parent f9dcb67 commit 87529bafa0ecfabe1316836414b0fec10c7c4581
Showing with 31 additions and 36 deletions.
  1. +2 −1 README.md
  2. +24 −32 examples/simple.js
  3. +4 −2 index.js
  4. +1 −1 package.json
View
@@ -11,9 +11,10 @@ Easy way for using tree routes in Express.js
### Create this
var express = require('express'),
+ treeRouter = require('express-treerouter')(express),
app = express();
- app.use(treeRouter(express, {
+ app.use(treeRouter({
'' : { get: controller },
'products': { get: controller, post: controller, content: {
':product_id': { get: controller, put: controller, del: controller, content: {
View
@@ -1,44 +1,36 @@
var express = require('express'),
- mapRouter = require('../index.js'),
+ treeRouter = require('../index.js')(express),
app = express();
-var sampleController = function(req, res){
+var controller = function(req, res){
res.send(req.method+' '+req.url);
};
+var error404Controller = function(req, res){
+ res.status(404);
+ res.send('404: '+req.method+' '+req.url);
+};
-var map = {
- 'products': {
- get: sampleController,
- post: sampleController,
- content: {
- ':product_id': {
- get: sampleController,
- put: sampleController,
- del: sampleController,
- content: {
- 'tags': {
- get: sampleController,
- },
- 'comments': {
- get: sampleController,
- post: sampleController,
- content: {
- ':comment_id': {
- get: sampleController,
- put: sampleController,
- del: sampleController
- }
- }
- }
- }
- }
- }
- }
+var tree = {
+ '' : { get: controller },
+ 'products': { get: controller, post: controller, content: {
+ ':product_id': { get: controller, put: controller, del: controller, content: {
+ 'tags': { get: controller, post: controller, content: {
+ ':tag_id': { get: controller, put: controller, del: controller }
+ }},
+ 'comments': { get: controller, post: controller, content: {
+ ':comment_id': { get: controller, put: controller, del: controller }
+ }},
+ 'owners': { get: controller, post: controller, content: {
+ ':owner_id': { get: controller, put: controller, del: controller }
+ }}
+ }}
+ }},
+ '*' : { all: error404Controller }
};
app.configure(function(){
- app.set('title', 'SimpleSample');
- app.use(mapRouter(map));
+ app.set('title', 'Simple');
+ app.use(treeRouter(tree));
});
app.listen(8000);
View
@@ -27,6 +27,8 @@ mapRouter.prototype.parse = function(routes, originPath){
});
};
-module.exports = function(express, routes){
- return new mapRouter(express, routes);
+module.exports = function( express ){
+ return function ( routes ) {
+ return new mapRouter(express, routes);
+ }
};
View
@@ -1,6 +1,6 @@
{
"name": "express-treerouter",
- "version": "0.2.1",
+ "version": "0.3.0",
"description": "Easy way for using tree routes in Express.js",
"keywords": [
"treeRouter",

0 comments on commit 87529ba

Please sign in to comment.