Socket
Socket
Sign inDemoInstall

decorator-router

Package Overview
Dependencies
18
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    decorator-router

framework agnostic router using es7 decorators


Version published
Weekly downloads
1
decreased by-88.89%
Maintainers
1
Install size
171 kB
Created
Weekly downloads
 

Readme

Source

decorator-router Build Status

Framework agnostic router using es7 decorators

Install

$ npm install --save decorator-router

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();
});

const

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');
});

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

  • express

Inspiration

I originaly wrote node-annotation-router Annotations names are inspired by Microsoft's MVC

License

MIT © Thomas Sileghem

FAQs

Last updated on 29 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc