emvici-router
High Performance express/connect pluggable router middleware
This Router should perform better than express.Router.
Installation
npm install --save emvici-router
Usage
Configuring middleware
You can simply create a router and plug it as a middleware using .use
method.
Connect
var connect = router = app = ; app;
Express
var express = router = app = ; app;
Route construction
var router = ; router
Options
type
- Defaults to: 'stack'
- Allowed Inputs: 'stack', 'wizard'
url
This will determine, by filtering url, which requests this route will run.
- Required
- Allowed Inputs:
String
;Regexp
;Array
ofStrings
;Array
of previous allowed inputs - Examples:
'/'
'/test/lol'
/^\/users\/(test|testa)/$
[ '/test', '/test/index' ]
stack
- Required when type is equal to
stack
- Allowed Inputs:
Function
;Array
of previous allowed inputs - Examples:
{ return Promise ; } { ; }
Structure convention
We recomend you to place a file called ./router.js
so you can save current app
router and allow Controllers or other modules on your system to load it up and
use it accordely:
// app.jsvar connect = ; var app = router = ; app;
// router.jsvar router = moduleexports = /* options */ throw404: false; router;
// controller/users.js var { // ...}; moduleexports = url: '/users' '/users/index' '/users/list' method: 'get' stack: someSemiNeededMiddleware { // ... } url: '/users/add' '/users/create' '/users/register' method: 'post' { // ... } ;