decorator-router-express
Express strategy for decorator-router
Install
$ npm install --save decorator-router decorator-router-express
Usage
Given a controller controller/homeCtrl.js
import {httpGet, middlewareFactory} from 'decorator-router';
const isLoggedIn = middlewareFactory(function(res, req, next){
next();
});
const isRole = middlewareFactory(role => function(res, req, next){
next();
});
export default {
@isLoggedIn
@httpGet('/')
getIndex(req, res){
res.ok();
},
@isRole('admin')
@httpGet('/admin')
getAdminPortal(req, res){
res.ok();
}
}
You can register those routes by doing:
import decoratorRouter = from 'decorator-router';
import decoratorRouterExpress = from 'decorator-router-express';
import express from 'express';
let app = express();
decoratorRouter('controller/*Ctrl.js', decoratorRouterExpress, app)
.then(x => {
console.log('done');
});
License
MIT © Thomas Sileghem