1.1.0 • Published 8 years ago

decorator-router-express v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

decorator-router-express Build Status

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

1.1.0

8 years ago

1.0.0

8 years ago