Framework agnostic router using es7 decorators
Install
$ npm install --save decorator-router
Usage
Given a controller controller/homeCtrl.js
; const isLoggedIn = ; const isRole = ; const @isLoggedIn @ { res; } @ @ { res; }
You can register those routes by doing
;;; let app = ; ;
API
decoratorRouter(patterns, strategy, ...strategyParameters)
patterns
Required
Type: string|Array
globby patterns
strategy
Required
Type: Function
the strategy used to register routes. See available strategies
strategyParameters
Type: Array
This will be passed to instantiate the strategy.
middlewareFactory(middleware)
Returns a decorator.
middleware
Required
Type: Function
Can be a middleware or a middleware factory depending if you need to pass parameters to your middleware or not.
@httpGet(url)
@httpPost(url)
@httpPut(url)
@httpDelete(url)
@httpHead(url)
url
Required
Type: string
Strategies
Inspiration
I originaly wrote node-annotation-router Annotations names are inspired by Microsoft's MVC
License
MIT © Thomas Sileghem