https://github.com/mastilver/decorator-router-express
express strategy for decorator-router
https://github.com/mastilver/decorator-router-express
Last synced: 6 months ago
JSON representation
express strategy for decorator-router
- Host: GitHub
- URL: https://github.com/mastilver/decorator-router-express
- Owner: mastilver
- License: mit
- Created: 2015-11-26T13:05:21.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-23T12:59:07.000Z (over 9 years ago)
- Last Synced: 2025-08-17T15:39:25.418Z (11 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# decorator-router-express [](https://travis-ci.org/mastilver/decorator-router-express)
> Express strategy for [decorator-router](https://github.com/mastilver/decorator-router)
## Install
```
$ npm install --save decorator-router decorator-router-express
```
## Usage
Given a controller `controller/homeCtrl.js`
```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:
```js
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](http://mastilver.com)