totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

feature-request: middleware negation flags #630

Closed AyushG3112 closed 6 years ago

AyushG3112 commented 6 years ago

Hi,

I have a middleware, say maintenance-mode-checker. I want to run this middleware for all my routes, excluding 3 specific ones. Is it possible to introduce negation flags in the system, so that global middlewares can be blocked from executed for specific routes?

For example, maybe I can do

F.route('/some-route',
    handler, // handler
    ['get', 'post', 'cors'], // normal flags
    ['maintenance-mode-checker'] // negation flags - DON'T run these middlewares
);
petersirka commented 6 years ago

Hi. I will think about it. Now you can use GROUP():

exports.install = function() {
    GROUP(['#middleware', 'authorize'], function() {
        ROUTE('/api/posts/', json_posts, ['put']);
        ROUTE('/api/commnets/', json_posts, ['post']);
    });
}

https://docs.totaljs.com/latest/en.html#api~Framework~F.group

petersirka commented 6 years ago

I thought about it and it would be useless. Thank you!