Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjirou/express-nested-router
Router combines namespace independent for the express 3.x
https://github.com/kjirou/express-nested-router
Last synced: 12 days ago
JSON representation
Router combines namespace independent for the express 3.x
- Host: GitHub
- URL: https://github.com/kjirou/express-nested-router
- Owner: kjirou
- Created: 2014-09-03T18:52:53.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T07:36:21.000Z (about 3 years ago)
- Last Synced: 2024-04-29T15:22:38.339Z (6 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.org/package/express-nested-router
- Size: 28.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
express-nested-router [![Build Status](https://travis-ci.org/kjirou/express-nested-router.svg?branch=master)](https://travis-ci.org/kjirou/express-nested-router)
=====================Router combines namespace independent for the [express](https://github.com/strongloop/express) 3.x.
## Examples
### Routing
```
var express = require('express');
var router = require('express-nested-router');var app = express();
var routes = router.namespace({
index: function(req, res, next){},
foo: function(req, res, next){},
bar: function(req, res, next){}
});routes.resolve(app);
//
// Routes:
// '/'
// '/bar'
// '/foo'
//
``````
var express = require('express');
var router = require('express-nested-router');var app = express();
var fooRoutes = router.namespace({
index: function(req, res, next){},
create: function(req, res, next){},
show: function(req, res, next){}
});var routes = router.namespace({
index: function(req, res, next){},
foo: fooRoutes,
bar: function(req, res, next){}
});routes.resolve(app);
//
// Routes:
// '/'
// '/bar'
// '/foo/'
// '/foo/create'
// '/foo/show'
//
``````
var express = require('express');
var router = require('express-nested-router');var app = express();
var fooControllers = {
index: function(req, res, next){},
show: function(req, res, next){}
};
var fooRoutes = router.namespace(fooControllers);var routes = router.namespace({
index: function(req, res, next){},
foo: fooRoutes,
});routes.reverseLookUp(fooControllers.show); // -> ['/foo/show']
routes.reverseLookUp(fooRoutes); // -> ['/foo']
```### Middlewares
```
var express = require('express');
var router = require('express-nested-router');var app = express();
var rountes = router.namespace({
index: function(req, res, next){
next();
}
});// Set middlewares applying before for each controllers and after.
rountes.pushBeforeMiddleware(function(req, res, next){
next();
});
rountes.pushAfterMiddleware(function(req, res, next){
next();
});rountes.resolve(app);
```### Chain middlewares to single controller by connect-chain
```
var chain = require('connect-chain');
var express = require('express');
var router = require('express-nested-router');var app = express();
var indexController = function(req, res, next){};
var beforeMiddleware = function(req, res, next){};
var afterMiddleware = function(req, res, next){};var chainedController = chain(beforeMiddleware, indexController, afterMiddleware);
var routes = router.namespace({
index: chainedController
});routes.resolve(app);
```## Development
- `node ~0.10.0`
- If you use the `0.11`, `power-assert` does not work correctly.