decorator-router-express
v1.1.0
Published
Express strategy for decorator-router
Downloads
4
Readme
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){
/* check if user is logged in */
next();
});
const isRole = middlewareFactory(role => function(res, req, next){
/* check if user have the right role */
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